/**
 *====================================================
 * 文件名称: FinanceAppActionApiImpl.java
 * 修订记录：
 * No    日期				作者(操作:具体内容)
 * 1.    2015年9月26日			chenxy(创建:创建文件)
 *====================================================
 * 类描述：(说明未实现或其它不应生成javadoc的内容)
 */
package com.yuexunit.finance.project.action.v1;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.apache.axis.utils.StringUtils;
import org.apache.commons.lang.ArrayUtils;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.yuexunit.account.action.v2.AccountActionApi;
import com.yuexunit.account.action.v2.model.AccountAlias;
import com.yuexunit.account.entity.AccountSessionEntity;
import com.yuexunit.core.BusinessException;
import com.yuexunit.core.ConfigPropertites;
import com.yuexunit.finance.bulkstock.entity.BulkstockInfoEntity;
import com.yuexunit.finance.bulkstock.service.TemporaryCreditlineEvaluationService;
import com.yuexunit.finance.common.util.BeanUtils;
import com.yuexunit.finance.common.util.ListSorter;
import com.yuexunit.finance.common.util.Page;
import com.yuexunit.finance.common.util.PageUtil;
import com.yuexunit.finance.context.FinanceBaseAction;
import com.yuexunit.finance.context.FinanceConstant;
import com.yuexunit.finance.context.FinanceSessionContext;
import com.yuexunit.finance.member.action.v1.EnterpriseActionApi;
import com.yuexunit.finance.member.action.v1.dto.EnterpriseCastor;
import com.yuexunit.finance.member.action.v1.model.EnterpriseBaseDetail;
import com.yuexunit.finance.member.action.v1.model.EnterpriseDetail;
import com.yuexunit.finance.member.action.v1.model.EnterpriseGradeEvaluation;
import com.yuexunit.finance.member.action.v1.model.EnterpriseGradeEvaluationDetail;
import com.yuexunit.finance.member.action.v1.model.FinanceBulkstockPledgeRateDetail;
import com.yuexunit.finance.member.action.v1.model.TemporaryCreditlineEvaluationDetail;
import com.yuexunit.finance.member.entity.EnterpriseEntity;
import com.yuexunit.finance.member.entity.EnterpriseGradeEntity;
import com.yuexunit.finance.member.entity.EnterpriseGradeEvaluationEntity;
import com.yuexunit.finance.member.entity.FinanceBulkstockPledgeRateEntity;
import com.yuexunit.finance.member.entity.TemporaryCreditlineEvaluationEntity;
import com.yuexunit.finance.member.entity.lexicon.AuditStateEnum;
import com.yuexunit.finance.member.service.EnterpriseGradeEvaluationService;
import com.yuexunit.finance.member.service.EnterpriseGradeService;
import com.yuexunit.finance.member.service.FinanceBulkstockPledgeRateService;
import com.yuexunit.finance.project.action.v1.dto.BulkstockCastor;
import com.yuexunit.finance.project.action.v1.dto.BulkstockPledgeCastor;
import com.yuexunit.finance.project.action.v1.dto.FinanceApplicationCastor;
import com.yuexunit.finance.project.action.v1.dto.FinanceLoanCastor;
import com.yuexunit.finance.project.action.v1.model.FiananceAuditInfo;
import com.yuexunit.finance.project.action.v1.model.FinanceAudit;
import com.yuexunit.finance.project.action.v1.model.FinanceBulkstock;
import com.yuexunit.finance.project.action.v1.model.FinanceEvidentiary;
import com.yuexunit.finance.project.action.v1.model.FinanceEvidentiaryCategory;
import com.yuexunit.finance.project.action.v1.model.FinanceMoneyStatement;
import com.yuexunit.finance.project.action.v1.model.FinanceTaskCount;
import com.yuexunit.finance.project.action.v1.model.InterestEstimate;
import com.yuexunit.finance.project.action.v1.model.PickupAuditInfo;
import com.yuexunit.finance.project.action.v1.model.input.EvaluationPrice;
import com.yuexunit.finance.project.action.v1.model.input.FinanceHandleWorkflow;
import com.yuexunit.finance.project.action.v1.model.input.Interest;
import com.yuexunit.finance.project.action.v1.model.input.NoticeHandleWorkflow;
import com.yuexunit.finance.project.action.v1.model.input.PickupHandleWorkflow;
import com.yuexunit.finance.project.action.v1.model.output.ContainerBulkstock;
import com.yuexunit.finance.project.action.v1.model.output.ContainerInventory;
import com.yuexunit.finance.project.action.v1.model.output.FinanceApplicationDetail;
import com.yuexunit.finance.project.action.v1.model.output.FinanceAuditLog;
import com.yuexunit.finance.project.action.v1.model.output.FinanceBulkstockView;
import com.yuexunit.finance.project.action.v1.model.output.FinanceEmployeeInfo;
import com.yuexunit.finance.project.action.v1.model.output.FinanceEvidentiaryCategoryOutput;
import com.yuexunit.finance.project.action.v1.model.output.FinanceFileOutput;
import com.yuexunit.finance.project.action.v1.model.output.FinanceFilesInfoDetail;
import com.yuexunit.finance.project.action.v1.model.output.FinanceGroupInfo;
import com.yuexunit.finance.project.action.v1.model.output.FinanceGroupMemberInfo;
import com.yuexunit.finance.project.action.v1.model.output.FinanceOrganInfo;
import com.yuexunit.finance.project.action.v1.model.output.FinanceTask;
import com.yuexunit.finance.project.action.v1.model.output.FinanceTaskApplyInfo;
import com.yuexunit.finance.project.action.v1.model.output.FinanceTaskGoodsInfo;
import com.yuexunit.finance.project.action.v1.model.output.FinanceTaskLoanInfo;
import com.yuexunit.finance.project.action.v1.model.output.FinanceTaskPickupInfo;
import com.yuexunit.finance.project.action.v1.model.output.LoanNoticeDetail;
import com.yuexunit.finance.project.action.v1.model.output.PickupApplicationDetail;
import com.yuexunit.finance.project.action.v1.model.output.PickupBulkstockWarehouseDetail;
import com.yuexunit.finance.project.action.v1.model.output.WareResultDetailData;
import com.yuexunit.finance.project.entity.FinanceApplicationEntity;
import com.yuexunit.finance.project.entity.FinanceAuditEntity;
import com.yuexunit.finance.project.entity.FinanceAuditLogEntity;
import com.yuexunit.finance.project.entity.FinanceBulkstockEntity;
import com.yuexunit.finance.project.entity.FinanceCompleteResultEntity;
import com.yuexunit.finance.project.entity.FinanceContactsEntity;
import com.yuexunit.finance.project.entity.FinanceEmployeeEntity;
import com.yuexunit.finance.project.entity.FinanceGroupEntity;
import com.yuexunit.finance.project.entity.FinanceGroupMemberEntity;
import com.yuexunit.finance.project.entity.FinanceMoneyStatementDetailsEntity;
import com.yuexunit.finance.project.entity.FinanceProductInnerEntity;
import com.yuexunit.finance.project.entity.InsuranceCoverageEntity;
import com.yuexunit.finance.project.entity.InsuranceEntity;
import com.yuexunit.finance.project.entity.LoanNoticeEntity;
import com.yuexunit.finance.project.entity.PickupApplicationEntity;
import com.yuexunit.finance.project.entity.PickupApplicationWarehouseEntity;
import com.yuexunit.finance.project.entity.PickupBulkstockWarehouseEntity;
import com.yuexunit.finance.project.entity.lexicon.ApiFinanceStateEnum;
import com.yuexunit.finance.project.entity.lexicon.ApiModuleTypeEnum;
import com.yuexunit.finance.project.entity.lexicon.ApiTypeEnum;
import com.yuexunit.finance.project.entity.lexicon.PickupMethodEnum;
import com.yuexunit.finance.project.entity.lexicon.ProductTypeEnum;
import com.yuexunit.finance.project.service.FinanceAuditLogService;
import com.yuexunit.finance.project.service.FinanceBulkstockService;
import com.yuexunit.finance.project.service.FinanceContactsService;
import com.yuexunit.finance.project.service.FinanceEmployeeService;
import com.yuexunit.finance.project.service.FinanceGroupService;
import com.yuexunit.finance.project.service.FinanceMoneyStatementDetailsService;
import com.yuexunit.finance.project.service.FinanceProductInnerService;
import com.yuexunit.finance.project.service.InsuranceCoverageService;
import com.yuexunit.finance.project.service.PickupApplicationWarehouseService;
import com.yuexunit.finance.project.service.PickupBulkstockWarehouseService;
import com.yuexunit.fs.action.InquireFileAction;
import com.yuexunit.fs.action.dto.DeleteFileActionInput;
import com.yuexunit.fs.action.dto.InquireFileOutput;
import com.yuexunit.inject.ComponentFactory;
import com.yuexunit.inject.annotation.Implements;
import com.yuexunit.organization.OrganizationActionApi;
import com.yuexunit.organization.castor.OrgDetailCastor;
import com.yuexunit.organization.dto.EmployeeListDto;
import com.yuexunit.organization.dto.InquireEmployeeDetailOutput;
import com.yuexunit.organization.dto.InquireOrganizationDetailOutput;
import com.yuexunit.organization.dto.InquireOrganizationTreeOutput;
import com.yuexunit.organization.entity.EmployeeEntity;
import com.yuexunit.organization.entity.OrganizationEntity;
import com.yuexunit.organization.entity.OrganizationExEntity;
import com.yuexunit.organization.service.EmployeeService;
import com.yuexunit.organization.service.OrganizationService;
import com.yuexunit.page.PageCriteria;
import com.yuexunit.page.PageList;
import com.yuexunit.permission.action.PermissionActionsApi;
import com.yuexunit.permission.action.dto.PermissionOutput;
import com.yuexunit.permission.action.dto.RoleListDto;
import com.yuexunit.persist.PersistUtil;
import com.yuexunit.persist.annotation.Transactional;
import com.yuexunit.persist.hibernate.SessionRepository;
import com.yuexunit.util.DateUtil;
import com.yuexunit.util.StringUtil;
import com.yuexunit.web.spi.SessionContext;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

/** 
 * @ClassName: FinanceAppActionApiImpl 
 * @Description: TODO  指尖金融app端接口管理实现
 * @author: NTBK-021-1010
 * @date: 2016年10月31日 下午3:39:49  
 */
@Implements(FinanceAppActionApi.class)
public class FinanceAppActionApiImpl  extends FinanceBaseAction implements FinanceAppActionApi{

	public static Logger logger = LoggerFactory.getLogger(FinanceAppActionApiImpl.class);

	private EnterpriseGradeEvaluationService enterpriseGradeEvaluationService = ComponentFactory.loadClass(EnterpriseGradeEvaluationService.class);

	private TemporaryCreditlineEvaluationService temporaryCreditlineEvaluationService = ComponentFactory.loadClass(TemporaryCreditlineEvaluationService.class);

	private FinanceBulkstockPledgeRateService financeBulkstockPledgeRateService = ComponentFactory.loadClass(FinanceBulkstockPledgeRateService.class);

	private EnterpriseGradeService enterpriseGradeService = ComponentFactory.loadClass(EnterpriseGradeService.class);

	private FinanceAuditLogService financeAuditLogService = ComponentFactory.loadClass(FinanceAuditLogService.class);

	private FinanceGroupService financeGroupService=ComponentFactory.loadClass(FinanceGroupService.class);

	private FinanceEmployeeService financeEmployeeService = ComponentFactory.loadClass(FinanceEmployeeService.class);

	private OrganizationService organizationService =ComponentFactory.loadClass(OrganizationService.class);

	private EmployeeService employeeService = (EmployeeService)ComponentFactory.loadClass(EmployeeService.class);

	private FinanceApplicationActionApi financeApplicationActionApi = ComponentFactory.loadClass(FinanceApplicationActionApi.class);

	private FinanceMoneyStatementDetailsService financeMoneyStatementDetailsService = (FinanceMoneyStatementDetailsService)ComponentFactory.loadClass(FinanceMoneyStatementDetailsService.class);

	private FinanceBulkstockService financeBulkstockService = ComponentFactory.loadClass(FinanceBulkstockService.class);

	private PickupBulkstockWarehouseService pickupBulkstockWarehouseService = ComponentFactory.loadClass(PickupBulkstockWarehouseService.class);

	private PickupApplicationWarehouseService pickupApplicationWarehouseService = ComponentFactory.loadClass(PickupApplicationWarehouseService.class);

	private FinancePickupApplicationWarehouseApi financePickupApplicationWarehouseApi = ComponentFactory.loadClass(FinancePickupApplicationWarehouseApi.class);
	
	private EnterpriseActionApi enterpriseActionApi = ComponentFactory.loadClass(EnterpriseActionApi.class);
	
	private FinanceLoanActionApi financeLoanActionApi = ComponentFactory.loadClass(FinanceLoanActionApi.class);
	
	private PermissionActionsApi permissionAction = ComponentFactory.loadClass(PermissionActionsApi.class);
	
	private FinanceProductInnerService financeProductInnerService = ComponentFactory.loadClass(FinanceProductInnerService.class);//融资产品信息
	
	private InsuranceCoverageService insuranceCoverageService = ComponentFactory.loadClass(InsuranceCoverageService.class);
	
	private FinanceBulkstockPledgeActionApi financeBulkstockPledgeActionApi = ComponentFactory.loadClass(FinanceBulkstockPledgeActionApi.class);
	
	private OrganizationActionApi organizationActionApi = ComponentFactory.loadClass(OrganizationActionApi.class);
	
	private InquireFileAction inquireFileAction = ComponentFactory.loadClass(InquireFileAction.class);
	
	private AccountActionApi accountAction = ComponentFactory.loadClass(AccountActionApi.class);
	
	private FinanceContactsService financeContactsService = ComponentFactory.loadClass(FinanceContactsService.class);

	@Override
	public FinanceTaskCount inquireFinanceTaskCount() throws Exception {
		FinanceTaskCount ftc = new FinanceTaskCount();

		//获取当前登录用户角色
		Long accountId=FinanceSessionContext.getAccountId();
		
		List<RoleListDto> rl = permissionAction.inquireAccountRoleList(accountId);  

		List<PermissionOutput>  permissionList = permissionAction.inquireCurrentOperationList(); //查询模块权限

		String[] arr=null;
		if(permissionList!=null){
			arr=new String[permissionList.size()];
			for(int i=0;i<permissionList.size();i++){
				if(permissionList.get(i)!=null)
					arr[i]=permissionList.get(i).getPermissionId();
			}
		}

		Session session = SessionRepository.getCurrentSession();

		if(ArrayUtils.contains(arr, ApiModuleTypeEnum.RZ.getCode())){  //查询是否有融资模块权限
			//查询待审批融资订单
			StringBuilder sql = new StringBuilder("SELECT * FROM FIN_FINANCE_APPLICATION WHERE FINANCE_STATE IN (1, 23);"); 
			Query query = session.createSQLQuery(sql.toString()).addEntity(FinanceApplicationEntity.class);
			List<FinanceApplicationEntity> financeEntities = query.list();
			for(FinanceApplicationEntity entities:financeEntities){

				//查询融资评审信息
				FinanceAuditEntity financeAudit = financeAuditService.inquireLatestFinanceAudit(entities.getFinanceId());
				if(financeAudit != null && financeAudit.getFinalState() == null) {
					continue;
				}//过滤老数据
				if(financeAudit == null) {
					financeAudit = new FinanceAuditEntity();
				}
				if(financeAudit.getFinalState() == null) {//第一个节点  融资评审表状态在保存才会生成
					financeAudit.setFinalState(ApiFinanceStateEnum.YW.getCode());
				}

				//判断当前流程节点
				if(taskCheckInfo(rl, financeAudit.getFinalState())){
					ftc.setFinanceCount(ftc.getFinanceCount() + 1);
				}
			}		
		}

		if(ArrayUtils.contains(arr, ApiModuleTypeEnum.FK.getCode())){  //查询是否有放款模块权限
			//查询放款申请订单
			//			List<LoanNoticeEntity> loanNoticeList = loanNoticeService.inquireInsuranceList();
			StringBuilder sql = new StringBuilder("SELECT * FROM FIN_LOAN_NOTICE WHERE ISNULL(AUDITOR_ID);"); 
			session = SessionRepository.getCurrentSession();
			Query query = session.createSQLQuery(sql.toString()).addEntity(LoanNoticeEntity.class);
			List<LoanNoticeEntity> loanNoticeList = query.list();
			for(LoanNoticeEntity entities: loanNoticeList){
				//查看放款评审信息
				//查询评审信息
				if(entities!=null) {
					//判断当前流程节点
					if(entities.getFinalState() != null && taskCheckInfo(rl, entities.getFinalState())){
						ftc.setLoanCount(ftc.getLoanCount() + 1);
					}
				}
			}
		}

		if(ArrayUtils.contains(arr, ApiModuleTypeEnum.TH.getCode())){  //查询是否有提货模块权限
			//查询提货申请订单
			//			List<PickupApplicationEntity> pickList=pickupApplicationService.inquirePickupApplicationList();

			StringBuilder sql = new StringBuilder("SELECT * FROM FIN_PICKUP_APPLICATION WHERE PICKUP_TYPE = 1 AND (APPLICATION_STATE = 1 OR (EXCHANGE_STATUS IN (1, 2, 3) AND APPLICATION_STATE = 2));"); 
			Query query = session.createSQLQuery(sql.toString()).addEntity(PickupApplicationEntity.class);
			List<PickupApplicationEntity> pickList = query.list();


			for(PickupApplicationEntity entities:pickList){
				//判断当前流程节点权限
				if(entities != null){
					if(entities.getFinalState() == null) {
						continue;
					} //以前数据不做审核流程	

					if(taskCheckInfo(rl,entities.getFinalState())){
						ftc.setPickupCount(ftc.getPickupCount() + 1);
					}
				}
			}			
		}

		//4.企业待审核用户
		if(ArrayUtils.contains(arr, ApiModuleTypeEnum.QYYH.getCode())){  //查询是否模块权限
			StringBuilder sql = new StringBuilder("SELECT * FROM FIN_ENTERPRISE WHERE AUDIT_STATE IN (1, 2) AND ENABLED = 1"); 
			Query query = session.createSQLQuery(sql.toString()).addEntity(EnterpriseEntity.class);
			List<EnterpriseEntity> pages = query.list();

			for (EnterpriseEntity entity : pages) {
				if(entity.getFinalState() == null) {
					continue;
				} //以前数据不做审核流程	
				if (ApiFinanceStateEnum.SCCWYY.getCode()==entity.getFinalState()) { //复核市场 &财务&运营
					if(taskCheckInfo(rl, ApiFinanceStateEnum.RYW.getCode()) || taskCheckInfo(rl, ApiFinanceStateEnum.ZJ.getCode()) || taskCheckInfo(rl, ApiFinanceStateEnum.YY.getCode())){  //角色复核市场
						ftc.setApproveCount(ftc.getApproveCount() + 1);
					}
				} else if (ApiFinanceStateEnum.SCCW.getCode()==entity.getFinalState()) {
					if(taskCheckInfo(rl, ApiFinanceStateEnum.RYW.getCode()) || taskCheckInfo(rl, ApiFinanceStateEnum.ZJ.getCode())){  //角色复核市场
						ftc.setApproveCount(ftc.getApproveCount() + 1);
					}
				} else if (ApiFinanceStateEnum.SCYY.getCode()==entity.getFinalState()) {
					if(taskCheckInfo(rl, ApiFinanceStateEnum.RYW.getCode()) || taskCheckInfo(rl, ApiFinanceStateEnum.YY.getCode())){  //角色复核市场
						ftc.setApproveCount(ftc.getApproveCount() + 1);
					}
				} else if (ApiFinanceStateEnum.CWYY.getCode()==entity.getFinalState()) {
					if(taskCheckInfo(rl, ApiFinanceStateEnum.ZJ.getCode()) || taskCheckInfo(rl, ApiFinanceStateEnum.YY.getCode())){  //角色复核市场
						ftc.setApproveCount(ftc.getApproveCount() + 1);
					}
				} else if(taskCheckInfo(rl, entity.getFinalState())){   //判断当然登入系统角色
					ftc.setApproveCount(ftc.getApproveCount() + 1);
				}
			}
		}

		//5.用户等级审核
		if(ArrayUtils.contains(arr, ApiModuleTypeEnum.YHDJ.getCode())){  //查询是否有用户等级
			//			List<EnterpriseGradeEvaluationEntity> pages = enterpriseGradeEvaluationService.inquireEnterpriseGradeEvaluationPageByStateList(new Integer[]{AuditStateEnum.UNAUDIT.ordinal(),AuditStateEnum.PASS.ordinal()});
			StringBuilder sql = new StringBuilder("SELECT * FROM FIN_ENTERPRISE_GRADE_EVALUATION WHERE AUDIT_STATE IN (1, 2)"); 
			Query query = session.createSQLQuery(sql.toString()).addEntity(EnterpriseGradeEvaluationEntity.class);
			List<EnterpriseGradeEvaluationEntity> pages = query.list();

			for (EnterpriseGradeEvaluationEntity entity : pages) {
				if(entity.getFinalState()==null){continue;} //以前数据不做审核流程	
				if (ApiFinanceStateEnum.SCCWYY.getCode()==entity.getFinalState()) { //复核市场 &财务&运营
					if(taskCheckInfo(rl, ApiFinanceStateEnum.RYW.getCode()) || taskCheckInfo(rl, ApiFinanceStateEnum.ZJ.getCode()) || taskCheckInfo(rl, ApiFinanceStateEnum.YY.getCode())){  //角色复核市场
						ftc.setGradeCount(ftc.getGradeCount() + 1);
					}
				} else if (ApiFinanceStateEnum.SCCW.getCode()==entity.getFinalState()) {
					if(taskCheckInfo(rl, ApiFinanceStateEnum.RYW.getCode()) || taskCheckInfo(rl, ApiFinanceStateEnum.ZJ.getCode())){  //角色复核市场
						ftc.setGradeCount(ftc.getGradeCount() + 1);
					}
				} else if (ApiFinanceStateEnum.SCYY.getCode()==entity.getFinalState()) {
					if(taskCheckInfo(rl, ApiFinanceStateEnum.RYW.getCode()) || taskCheckInfo(rl, ApiFinanceStateEnum.YY.getCode())){  //角色复核市场
						ftc.setGradeCount(ftc.getGradeCount() + 1);
					}
				} else if (ApiFinanceStateEnum.CWYY.getCode()==entity.getFinalState()) {
					if(taskCheckInfo(rl, ApiFinanceStateEnum.ZJ.getCode()) || taskCheckInfo(rl, ApiFinanceStateEnum.YY.getCode())){  //角色复核市场
						ftc.setGradeCount(ftc.getGradeCount() + 1);
					}
				} else if(taskCheckInfo(rl, entity.getFinalState())){   //判断当然登入系统角色
					ftc.setGradeCount(ftc.getGradeCount() + 1);
				}
			}
		}

		//6.临时额度调整
		if(ArrayUtils.contains(arr, ApiModuleTypeEnum.LSED.getCode())){  //查询是否有提货模块权限
			//			List<TemporaryCreditlineEvaluationEntity> pages = temporaryCreditlineEvaluationService.inquireTemporaryCreDitlineEvaluationByStatePageList(new Integer[]{AuditStateEnum.UNAUDIT.ordinal(),AuditStateEnum.PASS.ordinal()});

			StringBuilder sql = new StringBuilder("SELECT * FROM FIN_ENTERPRISE_TEMPORARY_CREDITLINE_EVALUATION WHERE AUDIT_STATE IN (1, 2)"); 
			Query query = session.createSQLQuery(sql.toString()).addEntity(TemporaryCreditlineEvaluationEntity.class);
			List<TemporaryCreditlineEvaluationEntity> pages = query.list();

			for (TemporaryCreditlineEvaluationEntity entity : pages) {
				if(entity.getFinalState()==null){continue;}  //以前数据不做审核流程
				if (ApiFinanceStateEnum.SCCWYY.getCode()==entity.getFinalState()) { //复核市场 &财务&运营
					if(taskCheckInfo(rl, ApiFinanceStateEnum.RYW.getCode()) || taskCheckInfo(rl, ApiFinanceStateEnum.ZJ.getCode()) || taskCheckInfo(rl, ApiFinanceStateEnum.YY.getCode())){  //角色复核市场
						ftc.setTemporaryCount(ftc.getTemporaryCount() + 1);
					}
				} else if (ApiFinanceStateEnum.SCCW.getCode()==entity.getFinalState()) {
					if(taskCheckInfo(rl, ApiFinanceStateEnum.RYW.getCode()) || taskCheckInfo(rl, ApiFinanceStateEnum.ZJ.getCode())){  //角色复核市场
						ftc.setTemporaryCount(ftc.getTemporaryCount() + 1);
					}
				} else if (ApiFinanceStateEnum.SCYY.getCode()==entity.getFinalState()) {
					if(taskCheckInfo(rl, ApiFinanceStateEnum.RYW.getCode()) || taskCheckInfo(rl, ApiFinanceStateEnum.YY.getCode())){  //角色复核市场
						ftc.setTemporaryCount(ftc.getTemporaryCount() + 1);
					}
				} else if (ApiFinanceStateEnum.CWYY.getCode()==entity.getFinalState()) {
					if(taskCheckInfo(rl, ApiFinanceStateEnum.ZJ.getCode()) || taskCheckInfo(rl, ApiFinanceStateEnum.YY.getCode())){  //角色复核市场
						ftc.setTemporaryCount(ftc.getTemporaryCount() + 1);
					}
				} else if(taskCheckInfo(rl, entity.getFinalState())){   //判断当然登入系统角色
					ftc.setTemporaryCount(ftc.getTemporaryCount() + 1);
				}
			}
		}

		//7.销售提货
		if(ArrayUtils.contains(arr, ApiModuleTypeEnum.XSTH.getCode())){  //查询是否有销售提货模块权限
			StringBuilder sql = new StringBuilder("SELECT * FROM FIN_PICKUP_APPLICATION_WAREHOUSE WHERE PICKUP_STATE IN (2, 10)"); 
			Query query = session.createSQLQuery(sql.toString()).addEntity(PickupApplicationWarehouseEntity.class);
			List<PickupApplicationWarehouseEntity> pages = query.list();

			for(PickupApplicationWarehouseEntity entities: pages){
				//查看放款评审信息
				//查询评审信息
				if(entities!=null) {
					//判断当前流程节点
					if(entities.getFinalState() != null && taskCheckInfo(rl, entities.getFinalState())){
						ftc.setPickupWarehouseCount(ftc.getPickupWarehouseCount() + 1);
					}
				}
			}
		}

		StringBuilder sb =new StringBuilder("select  t1.* from FIN_COMPLETE_RESULT as t1 JOIN (select z.* from FIN_AUDIT_LOG as z where z.ACCOUNT_ID="+accountId+"  group by z.AUDIT_TASK,z.AUDIT_JOIN_ID,z.ACCOUNT_ID) as t2 "+ 
				" on t1.PUBLIC_ID=t2.AUDIT_JOIN_ID and t1.TASKTYPE=t2.AUDIT_TASK where 1=1  "); 
		Query queryCount = session.createSQLQuery(sb.toString()).addEntity(FinanceCompleteResultEntity.class);
		List<FinanceCompleteResultEntity> countList=queryCount.list();

		Query query = session.createSQLQuery(sb.toString()).addEntity(FinanceCompleteResultEntity.class);
		List<FinanceCompleteResultEntity> resultList = query.list();
		for(FinanceCompleteResultEntity dto: resultList){
			if ("1".equals(dto.getTaskType())) {
				ftc.setFinanceCountCompleted(ftc.getFinanceCountCompleted() + 1);
			} else if ("2".equals(dto.getTaskType())) {
				ftc.setLoanCountCompleted(ftc.getLoanCountCompleted() + 1);
			} else if ("3".equals(dto.getTaskType())) {
				ftc.setPickupCountCompleted(ftc.getPickupCountCompleted() + 1);
			} else if ("4".equals(dto.getTaskType())) {
				ftc.setApproveCountCompleted(ftc.getApproveCountCompleted() + 1);
			} else if ("5".equals(dto.getTaskType())) {
				ftc.setGradeCountCompleted(ftc.getGradeCountCompleted() + 1);
			} else if ("6".equals(dto.getTaskType())) {
				ftc.setTemporaryCountCompleted(ftc.getTemporaryCountCompleted() + 1);
			}  else if ("7".equals(dto.getTaskType())) {
				ftc.setPickupWarehouseCountCompleted(ftc.getPickupWarehouseCountCompleted() + 1);
			} 
		}
		SessionRepository.closeCurrentSession();
		return ftc;
	}


	@Transactional
	@Override
	public PageList<FinanceTask> inquireFinanceTaskList1(Integer type, String companyName, PageCriteria page) throws Exception {

		if (null == type) {
			type = 0;
		}

		//获取当前登入用户角色
		Long accountId = FinanceSessionContext.getAccountId();
		List<RoleListDto> rl = permissionAction.inquireAccountRoleList(accountId);  

		List<PermissionOutput> permissionList=	permissionAction.inquireCurrentOperationList(); //查询模块权限
		List<FinanceTask> dataListOfOnePage=new ArrayList<FinanceTask>();

		String[] arr=null;
		if(permissionList != null){
			arr=new String[permissionList.size()];
			for(int i=0; i<permissionList.size(); i++){
				if(permissionList.get(i) != null) {
					arr[i]=permissionList.get(i).getPermissionId();
				}
			}
		}

		Session session = SessionRepository.getCurrentSession();

		if(ArrayUtils.contains(arr, ApiModuleTypeEnum.RZ.getCode()) && (type == 0 || type == 1)){  //查询是否有融资模块权限
			StringBuilder sql = new StringBuilder("SELECT * FROM FIN_FINANCE_APPLICATION WHERE FINANCE_STATE IN (1, 23);"); 
			Query query = session.createSQLQuery(sql.toString()).addEntity(FinanceApplicationEntity.class);
			List<FinanceApplicationEntity> financeEntities = query.list();

			//查询待审批融资订单
			//			FinanceInquireParams params = new FinanceInquireParams();
			//			params.setFinanceState(new Integer[]{FinanceStateEnum.APPROVE.ordinal(),FinanceStateEnum.WAIT_APPROVE.ordinal()});
			//			
			//			params.getPage().setPageSize(Integer.MAX_VALUE - 1);
			//			PageList<FinanceApplicationEntity> financeEntities = financeApplicationService.inquireFinanceList(params);
			for(FinanceApplicationEntity entities: financeEntities){

				FinanceTask task = new FinanceTask();
				//查询融资评审信息
				FinanceAuditEntity financeAudit = financeAuditService.inquireLatestFinanceAudit(entities.getFinanceId());
				if(financeAudit != null && financeAudit.getFinalState() == null) {
					continue;
				}//过滤老数据
				if(financeAudit == null) {
					financeAudit=new FinanceAuditEntity();
				}
				if(financeAudit.getFinalState() == null) {//第一个节点  融资评审表状态在保存才会生成
					financeAudit.setFinalState(ApiFinanceStateEnum.YW.getCode());
				}
				task.setFinanceId(entities.getFinanceId());
				task.setFinanceAuditId(financeAudit.getFinanceAuditId());
				task.setAuditNumber(financeAudit.getAuditNumber());
				task.setFinalState(financeAudit.getFinalState());  //当前节点状态
				task.setCallback(financeAudit.getCallback());
				task.setProductType(entities.getProductType().ordinal());
				List<FinanceBulkstockEntity> fbes = financeBulkstockService.inquireFinanceBulkstockList(entities.getFinanceId());
				if (fbes != null && fbes.size() > 0) {
					task.setBulkstockName(fbes.get(0).getBulkstockName());
				}

				//判断当前流程节点
				if(taskCheckInfo(rl, financeAudit.getFinalState())){
					task.setTaskType(ApiTypeEnum.RZ.getCode());
					task.setApplicationDateTime(entities.getApplicationDateTime());
					task.setEnterpriseName(entities.getEnterpriseName());
					// 融资货物
					for (FinanceBulkstockEntity c: fbes) {
						FinanceBulkstock bulkstock = BulkstockCastor.toFinanceBulkstock(c);
						FinanceBulkstockView view = new FinanceBulkstockView(bulkstock.getBulkstockName(), bulkstock.getQuantity(), bulkstock.getUnit());
						task.getBulkstocks().add(view);
					}
					task.setApplicationAmount(entities.getApplicationAmount());
					dataListOfOnePage.add(task);
				}
			}
		}

		if(ArrayUtils.contains(arr, ApiModuleTypeEnum.FK.getCode()) && (type == 0 || type == 2)){  //查询是否有放款模块权限
			//查询放款申请订单
			StringBuilder sql = new StringBuilder("SELECT * FROM FIN_LOAN_NOTICE WHERE ISNULL(AUDITOR_ID);"); 
			Query query = session.createSQLQuery(sql.toString()).addEntity(LoanNoticeEntity.class);
			List<LoanNoticeEntity> loanNoticeList = query.list();

			for(LoanNoticeEntity entities: loanNoticeList){
				FinanceTask task = new FinanceTask();
				FinanceApplicationEntity finance = financeApplicationService.inquireFinanceApplicationEntity(entities.getFinanceId());
				//查看放款评审信息
				//查询评审信息
				if(entities!=null){
					task.setCallback(entities.getCallback());
					task.setLoanNoticeId(entities.getLoanNoticeId());
					task.setAuditNumber(entities.getLoanNoticeNumber());  //放款编号
					task.setProductType(finance.getProductType().ordinal());
					List<FinanceBulkstockEntity> fbes = financeBulkstockService.inquireFinanceBulkstockList(entities.getFinanceId());
					if (fbes != null && fbes.size() > 0) {
						task.setBulkstockName(fbes.get(0).getBulkstockName());
					}

					//判断当前流程节点
					if(entities.getFinalState() != null && taskCheckInfo(rl, entities.getFinalState())){
						task.setTaskType(ApiTypeEnum.FK.getCode());
						task.setApplicationDateTime(entities.getApplyDate());
						task.setEnterpriseName(entities.getEnterpriseName());

						//查询融资信息
						FinanceApplicationEntity financeEntity = financeApplicationService.inquireFinanceApplicationEntity(entities.getFinanceId());
						task.setProductName(financeEntity.getProductName());     //产品信息

						// 融资货物
						for (FinanceBulkstockEntity c: fbes) {
							FinanceBulkstock bulkstock = BulkstockCastor.toFinanceBulkstock(c);
							FinanceBulkstockView view=new FinanceBulkstockView(bulkstock.getBulkstockName(),bulkstock.getQuantity(),bulkstock.getUnit());
							task.getBulkstocks().add(view);
						}
						task.setLoanAmount(entities.getLoanAmount());
						dataListOfOnePage.add(task);
					}
				}
			}
		}

		if(ArrayUtils.contains(arr, ApiModuleTypeEnum.TH.getCode()) &&  (type == 0 || type == 3)){  //查询是否有提货模块权限
			StringBuilder sql = new StringBuilder("SELECT * FROM FIN_PICKUP_APPLICATION WHERE PICKUP_TYPE = 1 AND (APPLICATION_STATE = 1 OR (EXCHANGE_STATUS IN (1, 2, 3) AND APPLICATION_STATE = 2));"); 
			Query query = session.createSQLQuery(sql.toString()).addEntity(PickupApplicationEntity.class);
			List<PickupApplicationEntity> pickList = query.list();

			//查询提货申请订单
			//			List<PickupApplicationEntity> pickList=pickupApplicationService.inquirePickupApplicationList();

			for(PickupApplicationEntity entities: pickList){
				//判断当前流程节点权限
				if(entities!=null){
					FinanceTask task=new FinanceTask();
					if(entities.getFinalState() == null){
						continue;
					} //以前数据不做审核流程	
					task.setFinalState(entities.getFinalState());  //当前节点状态
					task.setPickupId(entities.getPickupId());
					task.setCallback(entities.getCallback());
					FinanceApplicationEntity finance = financeApplicationService.inquireFinanceApplicationEntity(entities.getFinanceId());
					task.setProductType(finance.getProductType().ordinal());
					task.setPickupMethod(entities.getPickupMethod().getValue());
					List<FinanceBulkstockEntity> fbes = financeBulkstockService.inquireFinanceBulkstockList(entities.getFinanceId());
					if (fbes != null && fbes.size() > 0) {
						task.setBulkstockName(fbes.get(0).getBulkstockName());
					}

					if(taskCheckInfo(rl,entities.getFinalState())){
						//查询评审信息
						task.setAuditNumber(entities.getPickupNumber());
						task.setTaskType(ApiTypeEnum.TH.getCode());
						task.setApplicationDateTime(entities.getApplicantDateTime());
						task.setEnterpriseName(entities.getEnterpriseName());
						//查询提货信息
						// 融资货物
						List<FinanceBulkstockEntity> bulkstockList = financeBulkstockService.inquireFinanceBulkstockList(entities.getFinanceId());
						for (FinanceBulkstockEntity c : bulkstockList) {
							FinanceBulkstock bulkstock = BulkstockCastor.toFinanceBulkstock(c);
							FinanceBulkstockView view=new FinanceBulkstockView(bulkstock.getBulkstockName(),bulkstock.getQuantity(),bulkstock.getUnit());
							task.getBulkstocks().add(view);
						}
						PickupApplicationEntity entity = pickupApplicationService.inquirePickupApplication(entities.getPickupId());
						PickupApplicationDetail detail= BulkstockPledgeCastor.toPickupApplicationDetail(entity);
						task.setContainerInventorysCount(detail!=null&&detail.getContainerInventorys()!=null?detail.getContainerInventorys().size():0);
						dataListOfOnePage.add(task);
					}
				}
			}
		}

		//4.企业待审核用户
		if(ArrayUtils.contains(arr, ApiModuleTypeEnum.QYYH.getCode()) &&  (type == 0 || type == 4)){  //查询是否模块权限
			StringBuilder sql = new StringBuilder("SELECT * FROM FIN_ENTERPRISE WHERE AUDIT_STATE IN (1, 2)"); 
			Query query = session.createSQLQuery(sql.toString()).addEntity(EnterpriseEntity.class);
			List<EnterpriseEntity> pages = query.list();

			//			PageCriteria enterprise=new PageCriteria(1,Integer.MAX_VALUE-1);
			//			PageList<EnterpriseEntity> pages = enterpriseService.inquireEnterprisePageList("", AuditStateEnum.UNAUDIT, "", "", StateEnum.valueOf(0), null, null, null, null, enterprise);
			//			PageList<EnterpriseEntity> pagesPass = enterpriseService.inquireEnterprisePageList("", AuditStateEnum.PASS, "", "", StateEnum.valueOf(0), null, null, null, null, enterprise);
			//			if(pagesPass!=null)pages.addAll(pagesPass);
			for (EnterpriseEntity entity : pages) {
				if (null == entity.getFinalState()) {
					continue;
				}
				FinanceTask task=new FinanceTask();
				if(entity.getFinalState()==null){continue;} //以前数据不做审核流程	
				EnterpriseBaseDetail enterpriseBaseDetail=EnterpriseCastor.toEnterpriseBaseDetail(entity);
				task.setApplicationDateTime(enterpriseBaseDetail.getCreateDateTime());	//申请时间  排序使用
				task.setTaskType(ApiTypeEnum.QYYH.getCode());    //节点类型
				task.setFinalState(entity.getFinalState());  	 //当前节点状态  区分节点资料是填写，还是查看
				task.setEnterpriseId(entity.getEnterpriseId());  //企业enterpriseId
				task.setFrName(entity.getLegalPerson()); 			 //法人姓名   显示法人代表
				task.setEnterpriseName(entity.getEnterpriseName());
				task.setAuditNumber(entity.getAuditNumber());
				task.setCallback(entity.getCallback());
				if (ApiFinanceStateEnum.SCCWYY.getCode()==entity.getFinalState()) { //复核市场 &财务&运营
					if(taskCheckInfo(rl, ApiFinanceStateEnum.RYW.getCode()) || taskCheckInfo(rl, ApiFinanceStateEnum.ZJ.getCode()) || taskCheckInfo(rl, ApiFinanceStateEnum.YY.getCode())){  //角色复核市场
						dataListOfOnePage.add(task);
					}
				} else if (ApiFinanceStateEnum.SCCW.getCode()==entity.getFinalState()) {
					if(taskCheckInfo(rl, ApiFinanceStateEnum.RYW.getCode()) || taskCheckInfo(rl, ApiFinanceStateEnum.ZJ.getCode())){  //角色复核市场
						dataListOfOnePage.add(task);
					}
				} else if (ApiFinanceStateEnum.SCYY.getCode()==entity.getFinalState()) {
					if(taskCheckInfo(rl, ApiFinanceStateEnum.RYW.getCode()) || taskCheckInfo(rl, ApiFinanceStateEnum.YY.getCode())){  //角色复核市场
						dataListOfOnePage.add(task);
					}
				} else if (ApiFinanceStateEnum.CWYY.getCode()==entity.getFinalState()) {
					if(taskCheckInfo(rl, ApiFinanceStateEnum.ZJ.getCode()) || taskCheckInfo(rl, ApiFinanceStateEnum.YY.getCode())){  //角色复核市场
						dataListOfOnePage.add(task);
					}
				} else if(taskCheckInfo(rl, entity.getFinalState())){   //判断当然登入系统角色
					dataListOfOnePage.add(task);
				}
			}
		}

		//5.用户等级审核
		if(ArrayUtils.contains(arr, ApiModuleTypeEnum.YHDJ.getCode()) &&  (type == 0 || type == 5)){  //查询是否有用户等级
			StringBuilder sql = new StringBuilder("SELECT * FROM FIN_ENTERPRISE_GRADE_EVALUATION WHERE AUDIT_STATE IN (1, 2)"); 
			Query query = session.createSQLQuery(sql.toString()).addEntity(EnterpriseGradeEvaluationEntity.class);
			List<EnterpriseGradeEvaluationEntity> pages = query.list();

			//			List<EnterpriseGradeEvaluationEntity> pages = enterpriseGradeEvaluationService.inquireEnterpriseGradeEvaluationPageByStateList(new Integer[]{AuditStateEnum.UNAUDIT.ordinal(),AuditStateEnum.PASS.ordinal()});
			for (EnterpriseGradeEvaluationEntity entity : pages) {
				if (null == entity.getFinalState()) {
					continue;
				}
				FinanceTask task=new FinanceTask();
				if(entity.getFinalState()==null){continue;} //以前数据不做审核流程	
				EnterpriseGradeEvaluationDetail dto=EnterpriseCastor.toEnterpriseGradeEvaluationDetail(entity);
				task.setApplicationDateTime(dto.getEvaluationDateTime());    //评估时间  排序使用
				task.setTaskType(ApiTypeEnum.YHDJ.getCode());
				task.setFinalState(entity.getFinalState());      //节点判断
				task.setEnterpriseId(entity.getEnterpriseId());  //企业enterpriseId
				task.setEnterpriseName(dto.getEnterpriseName());
				task.setGradeEvaluationId(entity.getGradeEvaluationId());  //会员评估等级ID
				task.setCreditLine(dto.getCreditLine());         //授信额度
				task.setAuditNumber(entity.getAuditNumber());
				task.setCallback(entity.getCallback());
				if (ApiFinanceStateEnum.SCCWYY.getCode()==entity.getFinalState()) { //复核市场 &财务&运营
					if(taskCheckInfo(rl, ApiFinanceStateEnum.RYW.getCode()) || taskCheckInfo(rl, ApiFinanceStateEnum.ZJ.getCode()) || taskCheckInfo(rl, ApiFinanceStateEnum.YY.getCode())){  //角色复核市场
						dataListOfOnePage.add(task);
					}
				} else if (ApiFinanceStateEnum.SCCW.getCode()==entity.getFinalState()) {
					if(taskCheckInfo(rl, ApiFinanceStateEnum.RYW.getCode()) || taskCheckInfo(rl, ApiFinanceStateEnum.ZJ.getCode())){  //角色复核市场
						dataListOfOnePage.add(task);
					}
				} else if (ApiFinanceStateEnum.SCYY.getCode()==entity.getFinalState()) {
					if(taskCheckInfo(rl, ApiFinanceStateEnum.RYW.getCode()) || taskCheckInfo(rl, ApiFinanceStateEnum.YY.getCode())){  //角色复核市场
						dataListOfOnePage.add(task);
					}
				} else if (ApiFinanceStateEnum.CWYY.getCode()==entity.getFinalState()) {
					if(taskCheckInfo(rl, ApiFinanceStateEnum.ZJ.getCode()) || taskCheckInfo(rl, ApiFinanceStateEnum.YY.getCode())){  //角色复核市场
						dataListOfOnePage.add(task);
					}
				} else if(taskCheckInfo(rl, entity.getFinalState())){   //判断当然登入系统角色
					dataListOfOnePage.add(task);
				}
			}
		}

		//6.临时额度调整
		if(ArrayUtils.contains(arr, ApiModuleTypeEnum.LSED.getCode()) &&  (type == 0 || type == 6)){  //查询是否有临时额度模块权限
			StringBuilder sql = new StringBuilder("SELECT * FROM FIN_ENTERPRISE_TEMPORARY_CREDITLINE_EVALUATION WHERE AUDIT_STATE IN (1, 2)"); 
			Query query = session.createSQLQuery(sql.toString()).addEntity(TemporaryCreditlineEvaluationEntity.class);
			List<TemporaryCreditlineEvaluationEntity> pages = query.list();

			//			List<TemporaryCreditlineEvaluationEntity> pages = temporaryCreditlineEvaluationService.inquireTemporaryCreDitlineEvaluationByStatePageList(new Integer[]{AuditStateEnum.UNAUDIT.ordinal(),AuditStateEnum.PASS.ordinal()});
			for (TemporaryCreditlineEvaluationEntity entity : pages) {
				if (null == entity.getFinalState()) {
					continue;
				}
				FinanceTask task=new FinanceTask();
				if(entity.getFinalState()==null){continue;}  //以前数据不做审核流程
				TemporaryCreditlineEvaluationDetail detail = EnterpriseCastor.toTemporaryCreditlineEvaluationDetail(entity);
				task.setApplicationDateTime(entity.getEvaluationDateTime());    //评估时间  排序使用
				task.setTaskType(ApiTypeEnum.LSED.getCode());
				task.setFinalState(entity.getFinalState());      //节点判断
				task.setEnterpriseId(entity.getEnterpriseId());  //企业enterpriseId
				task.setEnterpriseName(detail.getEnterpriseName());
				task.setTemporaryCreditline(detail.getTemporaryCreditline());
				task.setTemporaryCreditlineEvaluationId(detail.getTemporaryCreditlineEvaluationId());
				task.setAuditNumber(entity.getAuditNumber());
				task.setCallback(entity.getCallback());
				if (ApiFinanceStateEnum.SCCWYY.getCode()==entity.getFinalState()) { //复核市场 &财务&运营
					if(taskCheckInfo(rl, ApiFinanceStateEnum.RYW.getCode()) || taskCheckInfo(rl, ApiFinanceStateEnum.ZJ.getCode()) || taskCheckInfo(rl, ApiFinanceStateEnum.YY.getCode())){  //角色复核市场
						dataListOfOnePage.add(task);
					}
				} else if (ApiFinanceStateEnum.SCCW.getCode()==entity.getFinalState()) {
					if(taskCheckInfo(rl, ApiFinanceStateEnum.RYW.getCode()) || taskCheckInfo(rl, ApiFinanceStateEnum.ZJ.getCode())){  //角色复核市场
						dataListOfOnePage.add(task);
					}
				} else if (ApiFinanceStateEnum.SCYY.getCode()==entity.getFinalState()) {
					if(taskCheckInfo(rl, ApiFinanceStateEnum.RYW.getCode()) || taskCheckInfo(rl, ApiFinanceStateEnum.YY.getCode())){  //角色复核市场
						dataListOfOnePage.add(task);
					}
				} else if (ApiFinanceStateEnum.CWYY.getCode()==entity.getFinalState()) {
					if(taskCheckInfo(rl, ApiFinanceStateEnum.ZJ.getCode()) || taskCheckInfo(rl, ApiFinanceStateEnum.YY.getCode())){  //角色复核市场
						dataListOfOnePage.add(task);
					}
				} else if(taskCheckInfo(rl, entity.getFinalState())){   //判断当然登入系统角色
					dataListOfOnePage.add(task);
				}
			}
		}

		//7.销售提货
		if(ArrayUtils.contains(arr, ApiModuleTypeEnum.XSTH.getCode()) &&  (type == 0 || type == 7)){  //查询是否有销售提货模块权限
			StringBuilder sql = new StringBuilder("SELECT * FROM FIN_PICKUP_APPLICATION_WAREHOUSE WHERE PICKUP_STATE IN (2, 10)"); 
			Query query = session.createSQLQuery(sql.toString()).addEntity(PickupApplicationWarehouseEntity.class);
			List<PickupApplicationWarehouseEntity> pages = query.list();

			for (PickupApplicationWarehouseEntity entity : pages) {
				if (null == entity.getFinalState()) {
					continue;
				}
				if(taskCheckInfo(rl, entity.getFinalState())){ 
					FinanceTask task = new FinanceTask();
					if(entity.getFinalState()==null){
						continue;
					}  //以前数据不做审核流程
					task.setApplicationDateTime(entity.getCreateDateTime());    //评估时间  排序使用
					task.setTaskType(ApiTypeEnum.XSTH.getCode());
					task.setFinalState(entity.getFinalState());      //节点判断
					task.setEnterpriseId(entity.getEnterpriseId());  //企业enterpriseId
					task.setEnterpriseName(entity.getEnterpriseName());
					task.setPickupId(entity.getPickupId());
					task.setAuditNumber(entity.getPickupNumber());
					task.setCallback(entity.getCallback());
					task.setCreateDateTime(entity.getCreateDateTime());
					task.setCreator(entity.getCreator());
					task.setUpdateDateTime(entity.getUpdateDateTime());
					task.setUpdator(entity.getUpdator());
					task.setProductType(entity.getProductType().ordinal());
					task.setBuyer(entity.getBuyer());
					task.setPickupMethod("自提");
					task.setDeliveryAddress(entity.getDeliveryAddress());

					BigDecimal pickupAmounts = BigDecimal.ZERO;
					BigDecimal pickupQuantitys = BigDecimal.ZERO;
					BigDecimal supervisionQuantitys = BigDecimal.ZERO;

					List<PickupBulkstockWarehouseEntity> pbwes = pickupBulkstockWarehouseService.inquirePickupBulkstockWarehouseList(entity.getPickupId(), null);
					for (PickupBulkstockWarehouseEntity pbwe : pbwes) {
						PickupBulkstockWarehouseDetail pbwd = new PickupBulkstockWarehouseDetail();
						BeanUtils.copyProperties(pbwe, pbwd);
						pbwd.setProductType(pbwe.getProductType().ordinal());

						StringBuffer sql1 = new StringBuffer();
						sql1.append("SELECT (T1.WEIGHT - IFNULL(T2.PICKUP_QUANTITY, 0)) as WEIGHT, T1.LOCATION_ID as LOCATION_ID, BULKSTOCK_NAME, SPECIFICATION, PRODUCT_TYPE, BULKSTOCK_INFO_ID, WAREHOUSE_NAME, T1.FINANCE_ID AS FINANCE_ID, T1.FINANCE_NUMBER AS FINANCE_NUMBER, T1.APPLICATION_DT AS APPLICATION_DT, T1.LOCATION_AREA AS LOCATION_AREA, T1.LOCATION_NAME AS LOCATION_NAME FROM (SELECT SUM(WEIGHT) AS WEIGHT, LOCATION_ID, BULKSTOCK_NAME, SPECIFICATION, c.PRODUCT_TYPE, BULKSTOCK_INFO_ID, WAREHOUSE_NAME, a.FINANCE_ID AS FINANCE_ID, a.FINANCE_NUMBER AS FINANCE_NUMBER, c.APPLICATION_DT AS APPLICATION_DT, a.LOCATION_AREA AS LOCATION_AREA, a.LOCATION_NAME AS LOCATION_NAME FROM fin_container_inventory a, fin_container_bulkstock b, fin_finance_application c WHERE a.INVENTORY_ID = b.INVENTORY_ID");
						sql1.append(" AND a.LOCATION_ID ='").append(pbwe.getLocationId() + "'");
						sql1.append(" AND a.FINANCE_NUMBER ='").append(pbwe.getFinanceNumber() + "'");
						sql1.append(" AND a.FINANCE_ID = c.FINANCE_ID AND c.FINANCE_STATE = 9 GROUP BY a.FINANCE_ID, LOCATION_ID) T1 LEFT JOIN (SELECT SUM(PICKUP_QUANTITY) AS PICKUP_QUANTITY, LOCATION_ID, FINANCE_NUMBER FROM fin_pickup_bulkstock_warehouse d, FIN_PICKUP_APPLICATION_WAREHOUSE e where d.PICKUP_ID = e.PICKUP_ID AND e.PICKUP_STATE NOT IN(1, 13) GROUP BY FINANCE_NUMBER, LOCATION_ID) T2 ON T1.LOCATION_ID = T2.LOCATION_ID AND T1.FINANCE_NUMBER = T2.FINANCE_NUMBER WHERE T1.LOCATION_ID IS NOT NULL AND T1.LOCATION_ID <> '';");

						List<Object> datas = session.createSQLQuery(sql1.toString()).addScalar("WEIGHT").addScalar("LOCATION_ID").addScalar("BULKSTOCK_NAME").addScalar("PRODUCT_TYPE").addScalar("BULKSTOCK_INFO_ID").addScalar("WAREHOUSE_NAME").addScalar("FINANCE_ID").addScalar("FINANCE_NUMBER").addScalar("LOCATION_NAME").addScalar("LOCATION_AREA").addScalar("APPLICATION_DT").addScalar("SPECIFICATION").list();
						for (Object l : datas) {
							Object[] os = (Object[])l;
							pbwd.setSupervisionQuantity((BigDecimal) os[0]);
							pbwd.setLocationName((String) os[8]);
							pbwd.setLocationArea((String) os[9]);
							pbwd.setFinanceApplicationDate((Date) os[10]);
							pbwd.setSpecifician((String) os[11]);
						}

						pickupAmounts = pickupAmounts.add(pbwd.getPickupAmount());
						pickupQuantitys = pickupQuantitys.add(pbwd.getPickupQuantity());
						supervisionQuantitys = supervisionQuantitys.add(pbwd.getSupervisionQuantity());

						task.getBulkstockList().add(pbwd);
					}

					task.setPickupAmounts(pickupAmounts);
					task.setPickupQuantitys(pickupQuantitys);
					task.setSupervisionQuantitys(supervisionQuantitys);
					if(taskCheckInfo(rl, entity.getFinalState())){   //判断当然登入系统角色
						dataListOfOnePage.add(task);
					}
				}
			}
		}

		//判断是否进行模糊查询
		if(!StringUtils.isEmpty(companyName)){
			Iterator<FinanceTask> it=dataListOfOnePage.iterator();
			while(it.hasNext()){
				FinanceTask task=it.next();
				if(task!=null && !StringUtils.isEmpty(task.getEnterpriseName()) && !task.getEnterpriseName().contains(companyName)){
					it.remove();
				}
			}
		}

		//按时间倒序
		ListSorter<FinanceTask> listSorter = new ListSorter<FinanceTask>(FinanceTask.class);
		listSorter.sort(dataListOfOnePage,"getApplicationDateTime","desc");

		Page pages=new Page();
		pages.setResult(dataListOfOnePage);
		pages.setPageNo(page.getPageIndex());
		pages.setPageSize(page.getPageSize());
		int [] param=PageUtil.init(page);
		List<FinanceTask> list=PageUtil.subList(param[0], param[1],pages);

		SessionRepository.closeCurrentSession();

		return new PageList<>(list, page, dataListOfOnePage.size());
	}


	/** 
	 * @Title: taskCheckInfo 角色权限确认
	 * @param rl		  拥有角色组
	 * @param finalState 当前节点审批角色
	 * @return
	 * @return: boolean
	 */
	public boolean taskCheckInfo(List<RoleListDto> rl,Long state){
		ApiFinanceStateEnum enums=ApiFinanceStateEnum.getByValue(state);
		for (RoleListDto rlt : rl) {
			if(rlt.getRoleName().equals(enums.getView())){
				return true;
			}
		}
		return false;
	}

	@Override
	public PageList<FinanceTask> inquireFinanceCompleteTaskList(Integer type, PageCriteria page,String companyName) {

		Long accountId=FinanceSessionContext.getAccountId();
		List<FinanceTask> data=new ArrayList<FinanceTask>();
		Session session = SessionRepository.getCurrentSession();
		//分页
		Page pages=new Page();
		pages.setPageNo(page.getPageIndex());
		pages.setPageSize(page.getPageSize());
		int [] param=PageUtil.init(page);
		int totalRecordCount=0;
		StringBuilder sb =new StringBuilder("select  t1.* from FIN_COMPLETE_RESULT as t1 JOIN (select z.* from FIN_AUDIT_LOG as z where z.ACCOUNT_ID="+accountId+"  group by z.AUDIT_TASK,z.AUDIT_JOIN_ID,z.ACCOUNT_ID) as t2 "+ 
				" on t1.PUBLIC_ID=t2.AUDIT_JOIN_ID and t1.TASKTYPE=t2.AUDIT_TASK where 1=1  "); 
		if(!StringUtils.isEmpty(companyName)){
			sb.append("and t1.ENTERPRISENAME like '%"+companyName+"%' ");
		}
		if(null != type && 0 != type){
			sb.append("and t1.TASKTYPE = '" + type + "' ");
		}
		Query queryCount = session.createSQLQuery(sb.toString()).addEntity(FinanceCompleteResultEntity.class);
		List<FinanceCompleteResultEntity> countList=queryCount.list();
		if(countList != null) {
			totalRecordCount=countList.size();
		}

		sb.append(" order by t1.APPLICATIONDATETIME desc LIMIT " + param[0] + "," + param[1] + ";");//limit起始条数,条数
		Query query = session.createSQLQuery(sb.toString()).addEntity(FinanceCompleteResultEntity.class);
		List<FinanceCompleteResultEntity> resultList = query.list();
		for(FinanceCompleteResultEntity dto:resultList){
			FinanceTask bean = new FinanceTask();
			BeanUtils.copyProperties(dto, bean);
			//			1:融资、2:放款、3:提货 、4：用户审核 、5:用户等级审核、 6：临时额度审核 7：代采代销 */
			if ("1".equals(dto.getTaskType()) || "2".equals(dto.getTaskType()) || "3".equals(dto.getTaskType())) {
				Long financeId =0L;
				if ("1".equals(dto.getTaskType())) {
					financeId = dto.getPublicId();
				} else if ("2".equals(dto.getTaskType())) {
					LoanNoticeEntity loan = loanNoticeService.inquireLoanNoticeEntity(dto.getPublicId());
					if (loan != null) {
						financeId = loan.getFinanceId();
					}
				} else if ("3".equals(dto.getTaskType())) {
					PickupApplicationEntity pickup = pickupApplicationService.inquirePickupApplication(dto.getPublicId());
					if (pickup != null) {
						financeId = pickup.getFinanceId();
						bean.setPickupMethod(pickup.getPickupMethod().getValue());
					}
				}
				if (financeId != 0L){
					FinanceApplicationEntity finance = financeApplicationService.inquireFinanceApplicationEntity(financeId);
					bean.setProductType(finance.getProductType().ordinal());
					List<FinanceBulkstockEntity> fbes = financeBulkstockService.inquireFinanceBulkstockList(financeId);
					if (fbes != null && fbes.size() > 0) {
						bean.setBulkstockName(fbes.get(0).getBulkstockName());
					}
				}
			} else if ("7".equals(dto.getTaskType())) {

				PickupApplicationWarehouseEntity pawe = pickupApplicationWarehouseService.inquirePickupApplicationWarehouseDetail(dto.getPublicId());
				List<PickupBulkstockWarehouseEntity> pbwes = pickupBulkstockWarehouseService.inquirePickupBulkstockWarehouseList(dto.getPublicId(), null);
				BigDecimal amount = BigDecimal.ZERO;
				BigDecimal quantity = BigDecimal.ZERO;
				for (PickupBulkstockWarehouseEntity pbwe : pbwes) {
					amount = amount.add(pbwe.getPickupAmount());
					quantity = quantity.add(pbwe.getPickupQuantity());
				}

				bean.setQuantity(quantity.longValue());
				bean.setPickupAmounts(amount);
				bean.setProductType(pawe.getProductType().ordinal());
				bean.setPickupQuantitys(quantity);
			}
			if(!StringUtils.isEmpty(dto.getBulkstockName()) && dto.getQuantity() != null) {
				bean.getBulkstocks().add(new FinanceBulkstockView(dto.getBulkstockName(), dto.getQuantity(), dto.getUnit()));
			}
			data.add(bean);
		}
		SessionRepository.closeCurrentSession();
		return new PageList<>(data, page, totalRecordCount);
	}

	@Override
	public FinanceTaskLoanInfo inquireFinanceLoadDetail(Long loanNoticeId) throws Exception {
		FinanceTaskLoanInfo loanInfo = new FinanceTaskLoanInfo();
		LoanNoticeEntity entity = loanNoticeService.inquireLoanNoticeEntity(loanNoticeId);
		if(entity==null){
			throw new Exception("放款信息查询不到！");
		}
		LoanNoticeDetail loanDetail = FinanceLoanCastor.toLoanNoticeDetail(entity);
		BeanUtils.copyProperties(loanDetail, loanInfo);
		loanInfo.setContainerInventorys(loanDetail.getContainerInventorys());
		loanInfo.setProductType(loanDetail.getProductType());

		if (5 == loanDetail.getProductType() || 6 == loanDetail.getProductType()) {
			for (int i = 0; i < loanInfo.getContainerInventorys().size(); i++) {
				WareResultDetailData wdd = financeApplicationActionApi.searchInboundInfoForFinanceDetail(loanInfo.getContainerInventorys().get(i).getCaseNumber());
				loanInfo.getContainerInventorys().get(i).setTallyPreFile(wdd.getResult().getPhotofile());
				loanInfo.getContainerInventorys().get(i).setTallySuffixFile(wdd.getResult().getPoundfile());
			}
		} else {
			for (int i = 0; i < loanInfo.getContainerInventorys().size(); i++) {
				StringBuffer pre = new StringBuffer("");
				StringBuffer suf = new StringBuffer("");
				for (String s : loanInfo.getContainerInventorys().get(i).getTallyPreFile().split(",")) {
					pre.append(ConfigPropertites.getProperties("UPLOAD_FILE") + s).append(",");
				}
				for (String s : loanInfo.getContainerInventorys().get(i).getTallySuffixFile().split(",")) {
					suf.append(ConfigPropertites.getProperties("UPLOAD_FILE") + s).append(",");
				}
				if (pre.length() > 0){
					pre.deleteCharAt(pre.length() - 1);
					loanInfo.getContainerInventorys().get(i).setTallyPreFile(pre.toString());
				}
				if (suf.length() > 0){
					suf.deleteCharAt(suf.length() - 1);
					loanInfo.getContainerInventorys().get(i).setTallySuffixFile(suf.toString());
				}
				for (int j = 0; j < loanInfo.getContainerInventorys().get(i).getContainerBulkstocks().size(); j++) {
					StringBuffer fuid = new StringBuffer("");
					for (String s : loanInfo.getContainerInventorys().get(i).getContainerBulkstocks().get(j).getFilesUuid().split(",")) {
						fuid.append(ConfigPropertites.getProperties("UPLOAD_FILE") + s).append(",");
					}
					if (fuid.length() > 0){
						fuid.deleteCharAt(fuid.length() - 1);
						loanInfo.getContainerInventorys().get(i).getContainerBulkstocks().get(j).setFilesUuid(fuid.toString());
					}
				}
			}
		}

		FinanceTaskApplyInfo ftai = inquireFinanceApplyDetail(entity.getFinanceId());
		loanInfo.setFinanceDays(ftai.getFinanceDays());
		loanInfo.setInterest(ftai.getInterest());
		loanInfo.setPledgeRate(ftai.getPledgeRate());

		//融资货物列表
		List<FinanceBulkstockView> bulList=new ArrayList<FinanceBulkstockView>();
		// 融资货物
		List<FinanceBulkstockEntity> bulkstockList = financeBulkstockService.inquireFinanceBulkstockList(entity.getFinanceId());
		BigDecimal totalWeight = BigDecimal.ZERO;
		BigDecimal totalNumber = BigDecimal.ZERO;
		if (bulkstockList != null && bulkstockList.size() > 0) {
			loanInfo.setBulkstockName(bulkstockList.get(0).getBulkstockName());
		}
		for (FinanceBulkstockEntity c : bulkstockList) {
			FinanceBulkstock bulkstock = BulkstockCastor.toFinanceBulkstock(c);
			FinanceBulkstockView view=new FinanceBulkstockView();
			BeanUtils.copyProperties(bulkstock, view);
			totalWeight=totalWeight.add(c.getWeight());
			totalNumber = totalNumber.add(c.getQuantity());
			bulList.add(view);
		}
		loanInfo.setBulkstocks(bulList);
		loanInfo.setTotalBoxSize(loanDetail.getContainerInventorys().size()); //总箱量
		loanInfo.setTotalWeight(totalWeight);  //货物总重
		loanInfo.setTotalNumber(totalNumber);  //件数
		return loanInfo;
	}

	@Override
	public FinanceTaskApplyInfo inquireFinanceApplyDetail(Long financeId) throws Exception {
		FinanceTaskApplyInfo bean = new FinanceTaskApplyInfo();
		FinanceApplicationEntity financeEntity = financeApplicationService.inquireFinanceApplicationEntity(financeId);
		if(financeEntity == null) {
			throw new Exception("融资信息申请查询不到!");
		}

		FinanceApplicationDetail financeDetail = FinanceApplicationCastor.toFinanceApplicationDetail(financeEntity);
		BeanUtils.copyProperties(financeDetail, bean);
		bean.setApplicationAmount(new BigDecimal(financeDetail.getApplicationAmount()));//申请金额
		bean.setSettlementMethod(financeDetail.getSettlementMethod());
		//查询企业授信额度

		EnterpriseDetail enterpriseDetail=enterpriseActionApi.inquireEnterpriseDetail(financeDetail.getEnterpriseId());
		if(enterpriseDetail!=null){  
			bean.setCreditQuota(enterpriseDetail.getCreditLine());//授信额度  new BigDecimal(financeDetail.getCreditQuota())
			bean.setCreditQuotaConsume(enterpriseDetail.getCreditRemaining());//可用额度   授信额度-已使用额度
		}
		
		if(financeDetail.getFinanceProductInnerDetail()!=null){
			bean.setInterest(financeDetail.getFinanceProductInnerDetail().getInterest());   //产品利率、年华利率
			bean.setFinanceDays(financeDetail.getFinanceProductInnerDetail().getFinanceDays());//融资天使
			bean.setFinanceProductInnerDetail(financeDetail.getFinanceProductInnerDetail());    /**产品信息---包含计息项目列表**/
		}
		
		if(financeDetail.getFinanceAuditDetail()!=null && financeDetail.getFinanceAuditDetail().getBail()!=null){
			bean.setBail(new BigDecimal(financeDetail.getFinanceAuditDetail().getBail()));//保证金
			bean.setBailRate(financeDetail.getFinanceAuditDetail().getBailRate());     //保证金比例
		}

		bean.setBulkstocks(financeDetail.getBulkstocks());     /**融资货物-保底-最高价格信息**/
		//查询融资产品信息
		FinanceProductInnerEntity innerEntity = financeProductInnerService.inquireFinanceProductInner(financeId, null);
		bean.setFinanceDays(innerEntity!=null && innerEntity.getFinanceDays()!=null?innerEntity.getFinanceDays():0);
		//质押率
		BigDecimal evaluateValuation=new BigDecimal(0);
		for(FinanceBulkstock b:financeDetail.getBulkstocks()){
			evaluateValuation=evaluateValuation.add(b.getEvaluateValuation());
		}

		FinanceAuditEntity financeAudit = financeAuditService.inquireLatestFinanceAudit(financeId); //查询评审信息
		if(financeAudit!=null){
			bean.setFinanceAuditId(financeAudit.getFinanceAuditId());
			bean.setAuditNumber(financeAudit.getAuditNumber());
			bean.setOpenQuota(financeAudit.getOpenQuota());
			bean.setSuperviseCharge(financeAudit.getSuperviseCharge());
			bean.setEstimateCost(financeAudit.getEstimateCost());
			bean.setEstimateIncome(financeAudit.getEstimateIncome());
			bean.setEstimateProfit(financeAudit.getEstimateProfit());
			bean.setFinanceAmount(financeAudit.getFinanceAmount());//批复金额
			bean.setFinalState(financeAudit.getFinalState());
			if(!evaluateValuation.equals(BigDecimal.ZERO) && bean.getFinanceAmount()!=null) { //质押率
				bean.setPledgeRate((bean.getFinanceAmount().multiply(BigDecimal.valueOf(100))).divide(evaluateValuation, 2, RoundingMode.HALF_UP));
			}
		}
		bean.setProductType(financeDetail.getProductType());
		if(bean.getFinanceProductInnerDetail()!=null) {
			bean.getFinanceProductInnerDetail().setProductType(financeDetail.getProductType());
		}
		return bean;
	}

	@Override
	public FinanceTaskGoodsInfo inquireFinanceApplyAllDetail(Long financeId) throws IllegalAccessException, InvocationTargetException {
		FinanceTaskGoodsInfo bean = new FinanceTaskGoodsInfo();
		FinanceApplicationEntity financeEntity = financeApplicationService.inquireFinanceApplicationEntity(financeId);
		FinanceApplicationDetail financeDetail = FinanceApplicationCastor.toFinanceApplicationDetail(financeEntity);
		BeanUtils.copyProperties(financeDetail, bean);
		bean.setBulkstocks(financeDetail.getBulkstocks());
		bean.setContainerBills(financeDetail.getContainerBills());
		InsuranceEntity insurance = insuranceService.inquireInsuranceEntityByFinanceId(financeId);
		List<InsuranceCoverageEntity> list=new ArrayList<InsuranceCoverageEntity>();
		if(insurance!=null){
			list=insuranceCoverageService.inquireInsuranceCoverageList(insurance.getInsuranceId());
			bean.setTotalAmount(insurance.getTotalAmount());
			bean.setInsuranceCompany(insurance.getInsuranceCompany());
			bean.setInsuranceNumber(insurance.getInsuranceNumber());
		}
		//平台保险信息
		InsuranceCoverageEntity insuranceCoverage=null;
		if (!list.isEmpty()) {
			insuranceCoverage=list.get(0);
			bean.setCoverageName(insuranceCoverage.getCoverageName());
			bean.setInsuranceAmount(insuranceCoverage.getInsuranceAmount());
		}


		return bean;
	}

	@Override
	public FinanceTaskPickupInfo inquireFinancePickupInfo(Long pickupId) throws Exception {
		if(pickupId == null) {
			throw new Exception("提货信息pickupId不能为空!");
		}
		FinanceTaskPickupInfo pickupInfo = new FinanceTaskPickupInfo();
		PickupApplicationEntity entity = pickupApplicationService.inquirePickupApplication(pickupId);
		PickupApplicationDetail pickupDetail = BulkstockPledgeCastor.toPickupApplicationDetail(entity);
		BeanUtils.copyProperties(pickupDetail, pickupInfo);
		pickupInfo.setPickupBulkstocks(pickupDetail.getPickupBulkstocks());

		pickupInfo.setContainerInventorys(pickupDetail.getContainerInventorys());    //装箱货物信息
		if (5 == pickupDetail.getProductType() || 6 == pickupDetail.getProductType()) {
			for (int i = 0; i < pickupInfo.getContainerInventorys().size(); i++) {
				WareResultDetailData wdd = financeApplicationActionApi.searchInboundInfoForFinanceDetail(pickupInfo.getContainerInventorys().get(i).getCaseNumber());
				pickupInfo.getContainerInventorys().get(i).setTallyPreFile(wdd.getResult().getPhotofile());
				pickupInfo.getContainerInventorys().get(i).setTallySuffixFile(wdd.getResult().getPoundfile());
			}
		} else {
			for (int i = 0; i < pickupInfo.getContainerInventorys().size(); i++) {
				StringBuffer pre = new StringBuffer("");
				StringBuffer suf = new StringBuffer("");
				for (String s : pickupInfo.getContainerInventorys().get(i).getTallyPreFile().split(",")) {
					pre.append(ConfigPropertites.getProperties("UPLOAD_FILE") + s).append(",");
				}
				for (String s : pickupInfo.getContainerInventorys().get(i).getTallySuffixFile().split(",")) {
					suf.append(ConfigPropertites.getProperties("UPLOAD_FILE") + s).append(",");
				}
				if (pre.length() > 0){
					pre.deleteCharAt(pre.length() - 1);
					pickupInfo.getContainerInventorys().get(i).setTallyPreFile(pre.toString());
				}
				if (suf.length() > 0){
					suf.deleteCharAt(suf.length() - 1);
					pickupInfo.getContainerInventorys().get(i).setTallySuffixFile(suf.toString());
				}
				for (int j = 0; j < pickupInfo.getContainerInventorys().get(i).getContainerBulkstocks().size(); j++) {
					StringBuffer fuid = new StringBuffer("");
					for (String s : pickupInfo.getContainerInventorys().get(i).getContainerBulkstocks().get(j).getFilesUuid().split(",")) {
						fuid.append(ConfigPropertites.getProperties("UPLOAD_FILE") + s).append(",");
					}
					if (fuid.length() > 0){
						fuid.deleteCharAt(fuid.length() - 1);
						pickupInfo.getContainerInventorys().get(i).getContainerBulkstocks().get(j).setFilesUuid(fuid.toString());
					}
				}
			}
		}

		pickupInfo.setExchangeBulkstockInfo(pickupDetail.getExchangeBulkstockInfo());
		pickupInfo.setExchangeContainerInventory(pickupDetail.getExchangeContainerInventory());   //换箱货物信息

		if (5 != pickupDetail.getProductType() && 6 != pickupDetail.getProductType()) {
			for (int i = 0; i < pickupInfo.getExchangeContainerInventory().size(); i++) {

				StringBuffer pre = new StringBuffer("");
				StringBuffer suf = new StringBuffer("");

				if (null != pickupInfo.getExchangeContainerInventory().get(i) && StringUtil.isNotBlank(pickupInfo.getExchangeContainerInventory().get(i).getTallyPreFile())) {
					for (String s : pickupInfo.getExchangeContainerInventory().get(i).getTallyPreFile().split(",")) {
						pre.append(ConfigPropertites.getProperties("UPLOAD_FILE") + s).append(",");
					}
				}
				if (null != pickupInfo.getExchangeContainerInventory().get(i) && StringUtil.isNotBlank(pickupInfo.getExchangeContainerInventory().get(i).getTallySuffixFile())) {
					for (String s : pickupInfo.getExchangeContainerInventory().get(i).getTallySuffixFile().split(",")) {
						suf.append(ConfigPropertites.getProperties("UPLOAD_FILE") + s).append(",");
					}
				}
				if (pre.length() > 0){
					pre.deleteCharAt(pre.length() - 1);
					pickupInfo.getExchangeContainerInventory().get(i).setTallyPreFile(pre.toString());
				}
				if (suf.length() > 0){
					suf.deleteCharAt(suf.length() - 1);
					pickupInfo.getExchangeContainerInventory().get(i).setTallySuffixFile(suf.toString());
				}
				for (int j = 0; j < pickupInfo.getExchangeContainerInventory().get(i).getExchangeContainerBulkstock().size(); j++) {
					StringBuffer fuid = new StringBuffer("");
					if (StringUtil.isBlank(pickupInfo.getExchangeContainerInventory().get(i).getExchangeContainerBulkstock().get(j).getFilesUuid())) {
						continue;
					}
					for (String s : pickupInfo.getExchangeContainerInventory().get(i).getExchangeContainerBulkstock().get(j).getFilesUuid().split(",")) {
						fuid.append(ConfigPropertites.getProperties("UPLOAD_FILE") + s).append(",");
					}
					if (fuid.length() > 0){
						fuid.deleteCharAt(fuid.length() - 1);
						pickupInfo.getExchangeContainerInventory().get(i).getExchangeContainerBulkstock().get(j).setFilesUuid(fuid.toString());
					}
				}
			}
		}

		pickupInfo.setFinalState(entity.getFinalState());
		
		//预计还款
		PickupApplicationDetail pickupApplicationDetail=financeBulkstockPledgeActionApi.inquireNormalPickupApplicationDetail(pickupId);
		pickupInfo.setEstimateAmount(pickupApplicationDetail!=null?pickupApplicationDetail.getEstimateAmount():BigDecimal.ZERO);
		//货物金额、货物利息
		List<Long> inventoryIds = pickupInventoryService.inquirePickupInventoryIdList(pickupId);
		if(inventoryIds!=null && inventoryIds.size()>0){
			InterestEstimate interestEstimate=financeLoanActionApi.interestEstimationFinanceInventory1(pickupDetail.getFinanceId(),inventoryIds.toArray(new Long[inventoryIds.size()]),pickupDetail.getDeliveryDate());
			pickupInfo.setFinanceValuation(interestEstimate.getPrincipal());
			pickupInfo.setBulkstockInterest(interestEstimate.getInterest());
		}

		//换箱
		logger.info("+++++++++="+pickupDetail.getPickupMethod()+"id:"+pickupId);
		if(pickupDetail.getPickupMethod().equals(PickupMethodEnum.EXCHANGE_CONTAINER.ordinal())){
			if(pickupDetail.getContainerInventorys()!=null)  //装箱货物信息
			{
				//装箱数量  containerInventorysSize
				//装箱数据
				BigDecimal containerInventorysAmount=BigDecimal.ZERO;
				for(ContainerInventory dto:pickupDetail.getContainerInventorys()){
					if(dto.getContainerBulkstocks()!=null){
						for(ContainerBulkstock bean: dto.getContainerBulkstocks()){
							containerInventorysAmount=containerInventorysAmount.add(bean.getFinanceValuation());
						}
					}
				}
				pickupInfo.setContainerInventorysAmount(containerInventorysAmount);

				// 换箱数量  exchangeContainerInventorySize
				//换箱数据
				BigDecimal exchangeContainerInventorysAmount=BigDecimal.ZERO;
				for(ContainerInventory dto:pickupDetail.getExchangeContainerInventorys()){
					if(dto.getContainerBulkstocks()!=null){
						for(ContainerBulkstock bean:dto.getContainerBulkstocks()){
							exchangeContainerInventorysAmount=exchangeContainerInventorysAmount.add(bean.getEvaluateValuation());
						}
					}
				}
				pickupInfo.setExchangeContainerInventorysAmount(exchangeContainerInventorysAmount);

			}
		}else if(pickupDetail.getPickupMethod().equals(PickupMethodEnum.CASH_DELIVERY.ordinal())){  //现金
			//查询货物金额信息
			if(!StringUtils.isEmpty(pickupInfo.getInterestInfo())){
				List<String> key = match(true,pickupInfo.getInterestInfo(), "span", "id");  //获取属性名
				List<String> value = match(false,pickupInfo.getInterestInfo(), "span", "id"); //获取属性值
				for(int i=0;i<key.size();i++){
					if(StringUtils.isEmpty(key.get(i)))continue;
					Class clazz=pickupInfo.getClass();
					StringBuilder sb = new StringBuilder(key.get(i));
					sb.setCharAt(0, Character.toUpperCase(sb.charAt(0)));
					Method m1 = clazz.getDeclaredMethod("set"+sb.toString(),BigDecimal.class);
					m1.invoke(pickupInfo, new BigDecimal(value.get(i).replace(",", "")));
				}
				//本次提货应还总额
				pickupInfo.setShouldReturn(pickupInfo.getFinanceValuation().add(pickupInfo.getBulkstockInterest()).add(pickupInfo.getAdjustAmount()));

				List<String> consentSumChineseList=match(false,pickupInfo.getInterestInfo(), "span", "style"); //大写金额
				if(consentSumChineseList!=null&&consentSumChineseList.size()>0)
					pickupInfo.setPickupConsentSumChinese(consentSumChineseList.get(0));
			}

			//现金提货 
			PageCriteria pages=new PageCriteria(1,Integer.MAX_VALUE-1);
			PageList<FinanceMoneyStatement> receivablesList=financeLoanActionApi.inquireReceiptMoneyStatementPageList(pickupInfo.getFinanceId(),new String[] { "RECEIVABLES"},null,null,null,null,null,null,null,true,null,pages);
			BigDecimal receivablesAmount=BigDecimal.ZERO;
			if(receivablesList!=null){
				for(FinanceMoneyStatement dto:receivablesList){
					if(dto!=null)receivablesAmount=receivablesAmount.add(dto.getAmount());
				}
			}
			pickupInfo.setReceivablesAmount(receivablesAmount);
			//pickupInfo.setReceivablesList(receivablesList);
			//显示还款明细、已还本金、利息
			PageList<FinanceMoneyStatement> financeMoneyList=financeLoanActionApi.inquireReceiptMoneyStatementPageList(pickupInfo.getFinanceId(),new String[] { "QUARTER_SETTLEMENT"},null,null,null,null,null,null,null,true,null, pages);
			if(financeMoneyList!=null){
				BigDecimal amount=BigDecimal.ZERO;
				for(FinanceMoneyStatement dto:financeMoneyList){
					if(dto==null)continue;
					amount=amount.add(dto.getAmount());
					List<FinanceMoneyStatementDetailsEntity> moneyStatementList=financeMoneyStatementDetailsService.inquireFinanceMoneyStatementDetailsList(dto.getMoneyStatementId(), pickupId, null);
					if(moneyStatementList==null)continue;
					for(FinanceMoneyStatementDetailsEntity bean:moneyStatementList){
						if(bean.getExpenseName().equals("货物利息")){
							amount=amount.add(bean.getExpense());
						}
					}
				}
				pickupInfo.setInterestAmount(amount);   //已还利息
			}
			//FinanceMoneyStatementDetailsService. List<FinanceMoneyStatementDetailsEntity> inquireFinanceMoneyStatementDetailsList(Long moneyStatementId, Long pickupId);
		}

		//换箱信息
		pickupInfo.setExchangeContainerInventorySize(pickupDetail.getExchangeContainerInventory()!=null?pickupDetail.getExchangeContainerInventory().size():0);
		if(pickupDetail.getExchangeBulkstockInfo()!=null && pickupDetail.getExchangeBulkstockInfo().size()>0){
			pickupInfo.setEvaluateValuation(pickupDetail.getExchangeBulkstockInfo().get(0).getEvaluateValuation());
			pickupInfo.setExchangeWeight(pickupDetail.getExchangeBulkstockInfo().get(0).getWeight());
		}
		//装箱信息
		pickupInfo.setContainerInventorysSize(pickupDetail.getContainerInventorys()!=null?pickupDetail.getContainerInventorys().size():0);
		if(pickupDetail.getPickupBulkstocks()!=null && pickupDetail.getPickupBulkstocks().size()>0){
			pickupInfo.setPickupWeight(pickupDetail.getPickupBulkstocks().get(0).getWeight());
			pickupInfo.setPickupValuation(pickupDetail.getPickupBulkstocks().get(0).getFinanceValuation());
		}
		return pickupInfo;
	}

	/** 
	 * 获取指定HTML标签的指定属性的值 
	 * @param boolean 类型
	 * @param source 要匹配的源文本 
	 * @param element 标签名称 
	 * @param attr 标签的属性名称 
	 * @return 属性值列表 
	 */  
	public static List<String> match(boolean type,String source, String element, String attr) {  
		List<String> result = new ArrayList<String>();  
		String reg="";
		if(type){
			reg = "<" + element + "[^<>]*?\\s" + attr + "=['\"]?(.*?)['\"]?(\\s.*?)?>";   //属性名称
		}else{
			reg="<\\s*" + element + "\\s.*?" + attr + "\\s*=\\s*[^>]*\\s*>\\s*(.*?)\\s*<\\s*/\\s*" + element + "\\s*>";  //属性值
		}
		Matcher m = Pattern.compile(reg).matcher(source);  
		while (m.find()) {  
			String r = m.group(1);  
			result.add(r);  
		}  
		return result;  
	} 

	@Override
	public List<FinanceAuditLog> auditWorkflowInfo(Long auditId, Long auditTask) {
		List<FinanceAuditLog> list=new ArrayList<FinanceAuditLog>();
		List<FinanceAuditLogEntity> auditLogList = new ArrayList<>();
		List<FinanceAuditLogEntity> ds = financeAuditLogService.inquireFinanceAuditLogList(auditId, auditTask);
		auditLogList.addAll(ds);
		if (1L == auditTask) {
			List<LoanNoticeEntity> loans = loanNoticeService.inquireLoanNoticeList(auditId);
			for (LoanNoticeEntity lne : loans) {
				List<FinanceAuditLogEntity> datas = financeAuditLogService.inquireFinanceAuditLogList(lne.getLoanNoticeId(), 2L);
				auditLogList.addAll(datas);
			}
		} else if (2L == auditTask) {
			LoanNoticeEntity loan = loanNoticeService.inquireLoanNoticeEntity(auditId);
			List<FinanceAuditLogEntity> datas = financeAuditLogService.inquireFinanceAuditLogList(loan.getFinanceId(), 1L);
			auditLogList.addAll(datas);
		}

		Collections.sort(auditLogList);

		//查询员工头像
		List<FinanceEmployeeEntity> empList = financeEmployeeService.inquireEmployList();
		Map<Long,FinanceEmployeeEntity> empMap=new HashMap<Long,FinanceEmployeeEntity>();
		if(empList!=null && empList.size()>0){
			for(FinanceEmployeeEntity en:empList){
				if(en!=null){
					if(!empMap.containsKey(en.getAccountId()))
						empMap.put(en.getAccountId(), en);
				}
			}
		}
		//EmployeeService employeeService;employeeService.inquireEmployee(arg0, arg1)
		Long tenantId=SessionContext.getTenantId();
		for(FinanceAuditLogEntity entity:auditLogList){
			FinanceAuditLog log=new FinanceAuditLog();

			BeanUtils.copyProperties(entity, log);
			//获取员工头像
			log.setPhotoId(empMap.get(entity.getAccountId())!=null?empMap.get(entity.getAccountId()).getPhotoId():"");
			//获取环信账号
			log.setHxAccount(empMap.get(entity.getAccountId())!=null?empMap.get(entity.getAccountId()).getCurrentArea():"");
			log.setEmpId(empMap.get(entity.getAccountId())!=null?empMap.get(entity.getAccountId()).getId():0l); //提货客户发起accountId 为空
			//如果发起是客户
			if(!entity.getRoleName().equals("客户")){
				log.setName(empMap.get(entity.getAccountId())!=null?empMap.get(entity.getAccountId()).getName():"");
			}else{
				EnterpriseEntity enterpriseEntity=enterpriseService.inquireEnterpriseFromAccountId(entity.getAccountId());
				log.setName(enterpriseEntity!=null?enterpriseEntity.getLegalPerson():"");
			}
			//查询员工详情
			if(log.getEmpId()!=null && log.getEmpId()!=0){
				InquireEmployeeDetailOutput empBean=organizationActionApi.inquireEmployeeDetail(log.getEmpId());
				log.setPosition(empBean!=null && empBean.getPositions()!=null &&empBean.getPositions().size()>0 && empBean.getPositions().get(0)!=null?empBean.getPositions().get(0).getPosition():"");
			}
			list.add(log);
		}
		return list;
	}

	@Override
	public List<InquireFileOutput> attachmentInfo(Long id, Long auditTask) throws Exception {
		List<InquireFileOutput> list=new ArrayList<InquireFileOutput>();
		Long financeId = null;
		if(auditTask==null)throw new Exception("auditTask节点类型不能为空");
		String uuids="";
		if(Long.valueOf(ApiTypeEnum.RZ.getCode())==auditTask){
			//materialFileuuid
			//			FinanceApplicationEntity financeEntity = financeApplicationService.inquireFinanceApplicationEntity(id);
			//		    FinanceApplicationCastor.toFinanceApplicationDetail(financeEntity);
		}else if(Long.valueOf(ApiTypeEnum.FK.getCode())==auditTask){
			//fileUuids
			LoanNoticeEntity entity = loanNoticeService.inquireLoanNoticeEntity(id);
			LoanNoticeDetail loanNotice=FinanceLoanCastor.toLoanNoticeDetail(entity);
			uuids=loanNotice.getFileUuids();
			financeId = entity.getFinanceId();
		}else if(Long.valueOf(ApiTypeEnum.TH.getCode())==auditTask){
			PickupApplicationEntity entity = pickupApplicationService.inquirePickupApplication(id);
			PickupApplicationDetail pickup=BulkstockPledgeCastor.toPickupApplicationDetail(entity);
			uuids = pickup.getFileUuids();
			financeId = entity.getFinanceId();
		}else if(Long.valueOf(ApiTypeEnum.XSTH.getCode())==auditTask){
			PickupApplicationWarehouseEntity entity = pickupApplicationWarehouseService.inquirePickupApplicationWarehouseDetail(id);
			uuids = entity.getFilesUuid();
		}
		String [] audits;
		if(!StringUtils.isEmpty(uuids)){
			audits=uuids.split(",");
			if(audits!=null && audits.length>0){
				for(int i=0;i<audits.length;i++){
					DeleteFileActionInput uuid=new DeleteFileActionInput();
					uuid.setFileUuid(audits[i]);
					InquireFileOutput inquireFileOutput=inquireFileAction.inquireFile(uuid);
					list.add(inquireFileOutput);
				}
			}
		}

		if (null != financeId) {
			FinanceApplicationDetail detail = financeApplicationActionApi.inquireFinanceApplicationDetail(financeId);
			//融资附件
			if (detail.getFinanceFilesInfoList() != null && !detail.getFinanceFilesInfoList().isEmpty()) {
				for (FinanceFilesInfoDetail ffid : detail.getFinanceFilesInfoList()) {
					if(!StringUtils.isEmpty(ffid.getFilesUuid())){
						audits=ffid.getFilesUuid().split(",");
						if(audits!=null && audits.length>0){
							for(int i=0;i<audits.length;i++){
								DeleteFileActionInput uuid=new DeleteFileActionInput();
								uuid.setFileUuid(audits[i]);
								InquireFileOutput inquireFileOutput=inquireFileAction.inquireFile(uuid);
								list.add(inquireFileOutput);
							}
						}
					}
				}
			}
		}
		return list;
	}

	@Override
	public List<FinanceEvidentiaryCategoryOutput> financeAttachmentInfo(Long financeId) throws Exception {
		if(financeId==null)throw new Exception("financeId不能为空");
		List<FinanceEvidentiaryCategoryOutput> outList=new ArrayList<FinanceEvidentiaryCategoryOutput>();
		FinanceApplicationEntity financeEntity = financeApplicationService.inquireFinanceApplicationEntity(financeId);
		FinanceApplicationDetail detail=FinanceApplicationCastor.toFinanceApplicationDetail(financeEntity);
		if(detail.getEvidentiaryCategorys()!=null){
			List<FinanceEvidentiaryCategory> list=detail.getEvidentiaryCategorys();
			for(FinanceEvidentiaryCategory category:list){

				FinanceEvidentiaryCategoryOutput financeEvidentiaryCategoryOutput=new FinanceEvidentiaryCategoryOutput();
				BeanUtils.copyProperties(category, financeEvidentiaryCategoryOutput);
				List<FinanceEvidentiary> evidentiaryList=category.getEvidentiarys();
				if(evidentiaryList!=null){
					List<FinanceFileOutput> fileList=new ArrayList<FinanceFileOutput>();
					for(FinanceEvidentiary evidentiary:evidentiaryList){
						if(evidentiary!=null && !StringUtils.isEmpty(evidentiary.getMaterialFileuuid())){
							FinanceFileOutput financeFileOutput=new FinanceFileOutput();
							BeanUtils.copyProperties(evidentiary, financeFileOutput);

							DeleteFileActionInput uuid=new DeleteFileActionInput();
							uuid.setFileUuid(evidentiary.getMaterialFileuuid());
							InquireFileOutput inquireFileOutput=inquireFileAction.inquireFile(uuid);
							BeanUtils.copyProperties(inquireFileOutput, financeFileOutput);
							fileList.add(financeFileOutput);
						}
					}
					financeEvidentiaryCategoryOutput.setEvidentiarys(fileList);
				}
				outList.add(financeEvidentiaryCategoryOutput);
			}
		}

		//融资协议附件
		if (detail.getFinanceProtocolDetail() != null && StringUtil.isNotBlank(detail.getFinanceProtocolDetail().getMaterials())) {
			FinanceEvidentiaryCategoryOutput feco = new FinanceEvidentiaryCategoryOutput();
			feco.setTemplateName("融资协议");
			List<FinanceFileOutput> fileList=new ArrayList<FinanceFileOutput>();
			for (String m : detail.getFinanceProtocolDetail().getMaterials().split(",")) {
				if (StringUtil.isNotBlank(m)) {
					FinanceFileOutput ffo = new FinanceFileOutput();
					DeleteFileActionInput uuid = new DeleteFileActionInput();
					uuid.setFileUuid(m);
					InquireFileOutput ifo = inquireFileAction.inquireFile(uuid);
					ffo.setCreateTime(ifo.getCreateTime());
					ffo.setFileName(ifo.getFileName());
					ffo.setFileSize(ifo.getFileSize());
					ffo.setFileUuid(ifo.getFileUuid());
					ffo.setMaterialFileuuid(ifo.getFileUuid());
					fileList.add(ffo);
				}
			}
			feco.setEvidentiarys(fileList);
			outList.add(feco);
		}

		//融资合同附件
		if (detail.getFinanceContractDetail() != null && StringUtil.isNotBlank(detail.getFinanceContractDetail().getMaterials())) {
			FinanceEvidentiaryCategoryOutput feco = new FinanceEvidentiaryCategoryOutput();
			feco.setTemplateName("融资合同");
			List<FinanceFileOutput> fileList=new ArrayList<FinanceFileOutput>();
			for (String m : detail.getFinanceContractDetail().getMaterials().split(",")) {
				if (StringUtil.isNotBlank(m)) {
					FinanceFileOutput ffo = new FinanceFileOutput();
					DeleteFileActionInput uuid = new DeleteFileActionInput();
					uuid.setFileUuid(m);
					InquireFileOutput ifo = inquireFileAction.inquireFile(uuid);
					ffo.setCreateTime(ifo.getCreateTime());
					ffo.setFileName(ifo.getFileName());
					ffo.setFileSize(ifo.getFileSize());
					ffo.setFileUuid(ifo.getFileUuid());
					ffo.setMaterialFileuuid(ifo.getFileUuid());
					fileList.add(ffo);
				}
			}
			feco.setEvidentiarys(fileList);
			outList.add(feco);
		}

		//融资附件
		if (detail.getFinanceFilesInfoList() != null && !detail.getFinanceFilesInfoList().isEmpty()) {
			for (FinanceFilesInfoDetail ffid : detail.getFinanceFilesInfoList()) {
				FinanceEvidentiaryCategoryOutput feco = new FinanceEvidentiaryCategoryOutput();
				feco.setTemplateName(ffid.getNormFileName());
				List<FinanceFileOutput> fileList = new ArrayList<FinanceFileOutput>();
				for (String m : ffid.getFilesUuid().split(",")) {
					if (StringUtil.isNotBlank(m)) {
						FinanceFileOutput ffo = new FinanceFileOutput();
						DeleteFileActionInput uuid = new DeleteFileActionInput();
						uuid.setFileUuid(m);
						InquireFileOutput ifo = inquireFileAction.inquireFile(uuid);
						ffo.setCreateTime(ifo.getCreateTime());
						ffo.setFileName(ifo.getFileName());
						ffo.setFileSize(ifo.getFileSize());
						ffo.setFileUuid(ifo.getFileUuid());
						ffo.setMaterialFileuuid(ifo.getFileUuid());
						fileList.add(ffo);
					}
				}
				feco.setEvidentiarys(fileList);
				outList.add(feco);
			}
		}

		return outList;
	}

	@Override
	public Map<String, Object> handleFinanceWorkflowInfo(
			FinanceHandleWorkflow financeHandleWorkflow) throws Exception {
		Map<String,Object> map=new HashMap<String,Object>();
		//		FinanceApplicationEntity finance = financeApplicationService.inquireFinanceApplicationEntity(financeHandleWorkflow.getFinanceId());
		//		financeHandleWorkflow.setProductType(finance.getProductType().ordinal());
		if(ApiTypeEnum.RZ.getCode().equals(financeHandleWorkflow.getTaskType())){ //融资
			if(financeHandleWorkflow.getFinanceId()==null){throw new Exception("融资信息ID不能为空!");}
			FinanceAuditEntity entity=financeAuditService.inquireLatestFinanceAudit(financeHandleWorkflow.getFinanceId());//查询当前节点信息
			FiananceAuditInfo fiananceAuditInfo=new FiananceAuditInfo();
			FinanceAudit financeAudit=new FinanceAudit();
			financeAudit.setMaterials("");  //手机审批默认不上传附件，兼容后面程序bug赋值""
			financeAudit.setFinanceDays(financeHandleWorkflow.getFinanceDays());
			financeAudit.setInterestPart(financeHandleWorkflow.getInterestPart());
			financeAudit.setSettlementMethod(financeHandleWorkflow.getSettlementMethod());
			//当前业务操作
			if(financeHandleWorkflow.getSubmitType().equals("0")){  //保存
				//业务-业务领导-运营-运营领导-风控-风控领导,只有领导有打回权限到一级权限 改变finalState状态
				if(entity==null || (entity.getFinalState()!=null && entity.getFinalState().equals(ApiFinanceStateEnum.YW.getCode()))){   //如果financeAuditEntity 为空流程在第一个节点，业务审批
					if(StringUtil.isNotBlank(financeHandleWorkflow.getFinanceAmount())) {
						financeAudit.setFinanceAmount(financeHandleWorkflow.getFinanceAmount().toString());
					} else {
						financeAudit.setFinanceAmount("0");
					}

					if(financeHandleWorkflow.getIntrerst()!=null)
						financeAudit.setAuditInterest(financeHandleWorkflow.getIntrerst().toString());
					BeanUtils.copyProperties(financeHandleWorkflow, financeAudit, "financeAmount");
					//货物估值信息转换
					if(!StringUtils.isEmpty(financeHandleWorkflow.getEvaluationPriceJson())){
						JSONArray json = JSONArray.fromObject(financeHandleWorkflow.getEvaluationPriceJson());
						List<EvaluationPrice> jsonlist=JSONArray.toList(json,EvaluationPrice.class);
						financeHandleWorkflow.setEvaluationPriceList(jsonlist);
						logger.info("jsonlist" + financeHandleWorkflow.getEvaluationPriceJson());

						if(financeHandleWorkflow.getEvaluationPriceList()!=null && financeHandleWorkflow.getEvaluationPriceList().size()>0){
							int size=financeHandleWorkflow.getEvaluationPriceList().size();
							Long [] bulkstockIds=new Long[size];
							BigDecimal [] evaluatePrice=new BigDecimal[size],lowestPrice=new BigDecimal[size],highestPrice=new BigDecimal[size],finalPrice=new BigDecimal[size];
							for(int i=0;i<size;i++){
								EvaluationPrice eva=financeHandleWorkflow.getEvaluationPriceList().get(i);
								bulkstockIds[i]=eva.getBulkstockIds();
								evaluatePrice[i]=eva.getEvaluatePrice();
								lowestPrice[i]=eva.getLowestPrice();
								highestPrice[i]=eva.getHighestPrice();
								finalPrice[i]=eva.getFinalPrice();
							}
							financeAudit.setBulkstockIds(bulkstockIds);
							financeAudit.setEvaluatePrice(evaluatePrice);
							financeAudit.setLowestPrice(lowestPrice);
							financeAudit.setHighestPrice(highestPrice);
							financeAudit.setFinalPrice(finalPrice);
						}
					}

					//计息费用转换
					if(!StringUtils.isEmpty(financeHandleWorkflow.getInterestJson())){
						JSONArray json = JSONArray.fromObject(financeHandleWorkflow.getInterestJson());
						List jsonlist=JSONArray.toList(json,Interest.class);
						financeHandleWorkflow.setInterestList(jsonlist);

						if(financeHandleWorkflow.getInterestList()!=null && financeHandleWorkflow.getInterestList().size()>0){
							int size=financeHandleWorkflow.getInterestList().size();
							Long[] financeProductInterestItemId=new Long[size];
							String[] financeProductInterestItemName=new String[size];
							Integer[] billingType=new Integer[size], startDay=new Integer[size], endDay=new Integer[size];
							BigDecimal[] interestRate=new BigDecimal[size];
							for(int i=0;i<size;i++){
								Interest interest=financeHandleWorkflow.getInterestList().get(i);
								financeProductInterestItemId[i]=interest.getFinanceProductInterestItemId();
								financeProductInterestItemName[i]=interest.getFinanceProductInterestItemName();
								billingType[i]=interest.getBillingType();
								startDay[i]=interest.getStartDay();
								endDay[i]=interest.getEndDay();
								interestRate[i]=interest.getInterestRate();
							}
							financeAudit.setFinanceProductInterestItemId(financeProductInterestItemId);
							financeAudit.setFinanceProductInterestItemName(financeProductInterestItemName);
							financeAudit.setBillingType(billingType);
							financeAudit.setStartDay(startDay);
							financeAudit.setEndDay(endDay);
							financeAudit.setInterestRate(interestRate);
						}
					}
					//提交
					financeAudit.setBusinessAudit(financeHandleWorkflow.getOpinion());
					financeAudit.setBusinessAuditState(financeHandleWorkflow.getSubmitState()==1?true:false);
					logger.info("----------业务保存状态:"+financeHandleWorkflow.getSubmitState());
					fiananceAuditInfo=financeApplicationActionApi.supplementBussinessAuditOpinion(financeAudit);
				}else if(entity.getFinalState().equals(ApiFinanceStateEnum.YWMANAGE.getCode())){
					financeAudit.setBusinessManageAudit(financeHandleWorkflow.getOpinion());
					financeAudit.setBusinessManageAuditState(financeHandleWorkflow.getSubmitState()==1?true:false);
					BeanUtils.copyProperties(financeHandleWorkflow, financeAudit);
					fiananceAuditInfo=financeApplicationActionApi.supplementBussinessManageAuditOpinion(financeAudit);
				}else if(entity.getFinalState().equals(ApiFinanceStateEnum.FK.getCode())){

					//风控正审，信息填写
					//					if(financeHandleWorkflow.getFinanceAmount()!=null)
					//					financeAudit.setFinanceAmount(financeHandleWorkflow.getFinanceAmount().toString());
					//					if(financeHandleWorkflow.getIntrerst()!=null)
					//					financeAudit.setAuditInterest(financeHandleWorkflow.getIntrerst().toString());
					//					BeanUtils.copyProperties(financeHandleWorkflow, financeAudit, "financeAmount");
					//					//货物估值信息转换
					//					if(!StringUtils.isEmpty(financeHandleWorkflow.getEvaluationPriceJson())){
					//						JSONArray json = JSONArray.fromObject(financeHandleWorkflow.getEvaluationPriceJson());
					//						List jsonlist=JSONArray.toList(json,EvaluationPrice.class);
					//						financeHandleWorkflow.setEvaluationPriceList(jsonlist);
					//						
					//						if(financeHandleWorkflow.getEvaluationPriceList()!=null && financeHandleWorkflow.getEvaluationPriceList().size()>0){
					//							int size=financeHandleWorkflow.getEvaluationPriceList().size();
					//							Long [] bulkstockIds=new Long[size];
					//							BigDecimal [] evaluatePrice=new BigDecimal[size],lowestPrice=new BigDecimal[size],highestPrice=new BigDecimal[size];
					//							for(int i=0;i<size;i++){
					//								EvaluationPrice eva=financeHandleWorkflow.getEvaluationPriceList().get(i);
					//								bulkstockIds[i]=eva.getBulkstockIds();
					//								evaluatePrice[i]=eva.getEvaluatePrice();
					//								lowestPrice[i]=eva.getLowestPrice();
					//								highestPrice[i]=eva.getHighestPrice();
					//							}
					//							financeAudit.setBulkstockIds(bulkstockIds);
					//							financeAudit.setEvaluatePrice(evaluatePrice);
					//							financeAudit.setLowestPrice(lowestPrice);
					//							financeAudit.setHighestPrice(highestPrice);
					//						}
					//					}
					//					//计息费用转换
					//					if(!StringUtils.isEmpty(financeHandleWorkflow.getInterestJson())){
					//						JSONArray json = JSONArray.fromObject(financeHandleWorkflow.getInterestJson());
					//						List jsonlist=JSONArray.toList(json,Interest.class);
					//						financeHandleWorkflow.setInterestList(jsonlist);
					//						
					//						if(financeHandleWorkflow.getInterestList()!=null && financeHandleWorkflow.getInterestList().size()>0){
					//							int size=financeHandleWorkflow.getInterestList().size();
					//							Long[] financeProductInterestItemId=new Long[size];
					//							String[] financeProductInterestItemName=new String[size];
					//							Integer[] billingType=new Integer[size],startDay=new Integer[size],endDay=new Integer[size];
					//							BigDecimal[] interestRate=new BigDecimal[size];
					//							for(int i=0;i<size;i++){
					//								Interest interest=financeHandleWorkflow.getInterestList().get(i);
					//								financeProductInterestItemId[i]=interest.getFinanceProductInterestItemId();
					//								financeProductInterestItemName[i]=interest.getFinanceProductInterestItemName();
					//								billingType[i]=interest.getBillingType();
					//								startDay[i]=interest.getStartDay();
					//								endDay[i]=interest.getEndDay();
					//								interestRate[i]=interest.getInterestRate();
					//							}
					//						financeAudit.setFinanceProductInterestItemId(financeProductInterestItemId);
					//						financeAudit.setFinanceProductInterestItemName(financeProductInterestItemName);
					//						financeAudit.setBillingType(billingType);
					//						financeAudit.setStartDay(startDay);
					//						financeAudit.setEndDay(endDay);
					//						financeAudit.setInterestRate(interestRate);
					//						}
					//					}

					financeAudit.setRiskAudit(financeHandleWorkflow.getOpinion());
					financeAudit.setRiskAuditState(financeHandleWorkflow.getSubmitState()==1?true:false);
					BeanUtils.copyProperties(financeHandleWorkflow, financeAudit);
					fiananceAuditInfo=financeApplicationActionApi.supplementRiskAuditOpinion(financeAudit);
				}else if(entity.getFinalState().equals(ApiFinanceStateEnum.FKMANAGE.getCode())){//风控领导节点
					financeAudit.setRiskMemberAudit(financeHandleWorkflow.getOpinion());
					financeAudit.setRiskMemberAuditState(financeHandleWorkflow.getSubmitState()==1?true:false);
					BeanUtils.copyProperties(financeHandleWorkflow, financeAudit);
					fiananceAuditInfo=financeApplicationActionApi.supplementRiskMemberAuditOpinion(financeAudit);
				}else if(entity.getFinalState().equals(ApiFinanceStateEnum.ZXMANAGE.getCode())){//执行董事节点
					financeAudit.setOperationManageAudit(financeHandleWorkflow.getOpinion());
					financeAudit.setOperationManageAuditState(financeHandleWorkflow.getSubmitState()==1?true:false);
					BeanUtils.copyProperties(financeHandleWorkflow, financeAudit);
					fiananceAuditInfo=financeApplicationActionApi.supplementOperationManageAuditOpinion(financeAudit);
				}else if(entity.getFinalState().equals(ApiFinanceStateEnum.SWMANAGE.getCode())){//业务领导
					financeAudit.setBusinessManageAudit(financeHandleWorkflow.getOpinion());
					financeAudit.setBusinessManageAuditState(financeHandleWorkflow.getSubmitState()==1?true:false);
					BeanUtils.copyProperties(financeHandleWorkflow, financeAudit);
					fiananceAuditInfo=financeApplicationActionApi.supplementBussinessManageAuditOpinion(financeAudit);
				}else if(entity.getFinalState().equals(ApiFinanceStateEnum.ZJ.getCode())){//财务确认
					financeAudit.setOperationAudit(financeHandleWorkflow.getOpinion());
					financeAudit.setOperationAuditState(financeHandleWorkflow.getSubmitState()==1?true:false);
					BeanUtils.copyProperties(financeHandleWorkflow, financeAudit);
					fiananceAuditInfo=financeApplicationActionApi.supplementOperationAuditOpinion(financeAudit);
				}
				map.put("fiananceAuditInfo", fiananceAuditInfo);
			}else if(financeHandleWorkflow.getSubmitType().equals("1")){  //提交只需要提供financeAuditId
				entity=financeAuditService.inquireLatestFinanceAudit(financeHandleWorkflow.getFinanceId());//查询当前节点信息
				if(entity==null){throw new Exception("融资审核信息查询不到!");}
				if(entity.getFinanceAuditId()==null){throw new Exception("融资审核信息ID为空!");}
				BeanUtils.copyProperties(entity, financeAudit);
				if (entity.getFinanceAmount() != null) {
					financeAudit.setFinanceAmount(entity.getFinanceAmount().toString());
				} else {
					financeAudit.setFinanceAmount("0");
				}
				logger.info("------------financeId:"+financeAudit.getFinanceId());
				//业务-业务领导-运营-运营领导-风控-风控领导,只有领导有打回权限到一级权限 改变finalState状态
				if(entity.getFinalState().equals(ApiFinanceStateEnum.YW.getCode())){
					//业务审核意见
					//提交
					financeAudit.setBusinessAudit(financeHandleWorkflow.getOpinion());
					financeAudit.setBusinessAuditState(financeHandleWorkflow.getSubmitState()==1?true:false);
					financeAudit.setDeviceType("提交");
					financeApplicationActionApi.submitBussinessAuditOpinion(financeAudit);
					logger.info("----------业务提交状态:"+financeHandleWorkflow.getSubmitState());
				}else if(entity.getFinalState().equals(ApiFinanceStateEnum.YWMANAGE.getCode())){
					financeAudit.setBusinessManageAudit(financeHandleWorkflow.getOpinion());
					financeAudit.setBusinessManageAuditState(financeHandleWorkflow.getSubmitState()==1?true:false);
					financeApplicationActionApi.submitBussinessManageAuditOpinion(financeAudit);
				}else if(entity.getFinalState().equals(ApiFinanceStateEnum.FK.getCode())){
					financeAudit.setRiskAudit(financeHandleWorkflow.getOpinion());
					financeAudit.setRiskAuditState(financeHandleWorkflow.getSubmitState()==1?true:false);
					financeAudit.setDeviceType("提交");
					financeApplicationActionApi.submitRiskAuditOpinion(financeAudit);
				}else if(entity.getFinalState().equals(ApiFinanceStateEnum.FKMANAGE.getCode())){
					financeAudit.setRiskMemberAudit(financeHandleWorkflow.getOpinion());
					financeAudit.setRiskMemberAuditState(financeHandleWorkflow.getSubmitState()==1?true:false);
					financeAudit.setDeviceType("提交");
					financeApplicationActionApi.submitRiskMemberAuditOpinion(financeAudit);
				}else if(entity.getFinalState().equals(ApiFinanceStateEnum.ZXMANAGE.getCode())){//执行董事节点
					financeAudit.setOperationManageAudit(financeHandleWorkflow.getOpinion());
					financeAudit.setOperationManageAuditState(financeHandleWorkflow.getSubmitState()==1?true:false);
					financeAudit.setDeviceType("提交");
					financeApplicationActionApi.submitOperationManageAuditOpinion(financeAudit);
				}else if(entity.getFinalState().equals(ApiFinanceStateEnum.SWMANAGE.getCode())){//业务领导
					financeAudit.setBusinessManageAudit(financeHandleWorkflow.getOpinion());
					financeAudit.setBusinessManageAuditState(financeHandleWorkflow.getSubmitState()==1?true:false);
					BeanUtils.copyProperties(financeHandleWorkflow, financeAudit);
					financeApplicationActionApi.submitBussinessManageAuditOpinion(financeAudit);
				}else if(entity.getFinalState().equals(ApiFinanceStateEnum.ZJ.getCode())){//业务领导
					financeAudit.setOperationAudit(financeHandleWorkflow.getOpinion());
					financeAudit.setOperationAuditState(financeHandleWorkflow.getSubmitState()==1?true:false);
					BeanUtils.copyProperties(financeHandleWorkflow, financeAudit);
					financeApplicationActionApi.submitOperationAuditOpinion(financeAudit);
				}

			}

		}
		return map;
	}

	@Override
	public Map<String, Object> handleLoanNoticeWorkflowInfo(
			NoticeHandleWorkflow financeHandleWorkflow) throws Exception {
		//审核类型 1:风控审核/ 2:风控分管领导审核/ 3:资金审核/ 4:资金分管领导审核 /5:总经理审核 /6:董事审核
		Map<String,Object> map=new HashMap<String,Object>();
		if(ApiTypeEnum.FK.getCode().equals(financeHandleWorkflow.getTaskType())){  //放款
			if(financeHandleWorkflow.getLoanNoticeId()==null){throw new Exception("放款信息ID不能为空！"); } //查询当前节点信息 
			LoanNoticeEntity entity = loanNoticeService.inquireLoanNoticeEntity(financeHandleWorkflow.getLoanNoticeId());
			//当前业务操作
			if(financeHandleWorkflow.getSubmitType().equals("0")){  //保存
				//财务-财务领导-总经理
				if(entity.getFinalState().equals(ApiFinanceStateEnum.ZJ.getCode())){
					financeLoanActionApi.saveLoanNoticeAudit(3,financeHandleWorkflow.getOpinion(),
							financeHandleWorkflow.getSubmitState()==1?true:false,financeHandleWorkflow.getLoanNoticeId(),null);
				}else if(entity.getFinalState().equals(ApiFinanceStateEnum.ZJMANAGE.getCode())){
					financeLoanActionApi.saveLoanNoticeAudit(4,financeHandleWorkflow.getOpinion(),
							financeHandleWorkflow.getSubmitState()==1?true:false,financeHandleWorkflow.getLoanNoticeId(),null);
				}else if(entity.getFinalState().equals(ApiFinanceStateEnum.TMANAGE.getCode())){
					financeLoanActionApi.saveLoanNoticeAudit(5,financeHandleWorkflow.getOpinion(),
							financeHandleWorkflow.getSubmitState()==1?true:false,financeHandleWorkflow.getLoanNoticeId(),null);
				}else if(entity.getFinalState().equals(ApiFinanceStateEnum.FMANAGE.getCode())){
					financeLoanActionApi.saveLoanNoticeAudit(6,financeHandleWorkflow.getOpinion(),
							financeHandleWorkflow.getSubmitState()==1?true:false,financeHandleWorkflow.getLoanNoticeId(),null);
				}else if(entity.getFinalState().equals(ApiFinanceStateEnum.ZXMANAGE.getCode())){
					financeLoanActionApi.saveLoanNoticeAudit(7,financeHandleWorkflow.getOpinion(),
							financeHandleWorkflow.getSubmitState()==1?true:false,financeHandleWorkflow.getLoanNoticeId(),null);
				}
			}else if(financeHandleWorkflow.getSubmitType().equals("1")){  //提交
				//财务-财务领导-总经理
				if(entity.getFinalState().equals(ApiFinanceStateEnum.ZJ.getCode())){
					financeLoanActionApi.submitLoanNoticeAudit(3,financeHandleWorkflow.getOpinion(),
							financeHandleWorkflow.getSubmitState()==1?true:false,financeHandleWorkflow.getLoanNoticeId(),null);
				}else if(entity.getFinalState().equals(ApiFinanceStateEnum.ZJMANAGE.getCode())){
					financeLoanActionApi.submitLoanNoticeAudit(4,financeHandleWorkflow.getOpinion(),
							financeHandleWorkflow.getSubmitState()==1?true:false,financeHandleWorkflow.getLoanNoticeId(),null);
				}else if(entity.getFinalState().equals(ApiFinanceStateEnum.TMANAGE.getCode())){
					financeLoanActionApi.submitLoanNoticeAudit(5,financeHandleWorkflow.getOpinion(),
							financeHandleWorkflow.getSubmitState()==1?true:false,financeHandleWorkflow.getLoanNoticeId(),null);
				}else if(entity.getFinalState().equals(ApiFinanceStateEnum.FMANAGE.getCode())){
					financeLoanActionApi.submitLoanNoticeAudit(6,financeHandleWorkflow.getOpinion(),
							financeHandleWorkflow.getSubmitState()==1?true:false,financeHandleWorkflow.getLoanNoticeId(),null);
				}else if(entity.getFinalState().equals(ApiFinanceStateEnum.ZXMANAGE.getCode())){
					financeLoanActionApi.submitLoanNoticeAudit(7,financeHandleWorkflow.getOpinion(),
							financeHandleWorkflow.getSubmitState()==1?true:false,financeHandleWorkflow.getLoanNoticeId(),null);
				}
			}


		}
		return map;
	}

	@Override
	public Map<String, Object> handlePickupWorkflowInfo(
			PickupHandleWorkflow financeHandleWorkflow) throws Exception {
		Map<String,Object> map=new HashMap<String,Object>();
		if(ApiTypeEnum.TH.getCode().equals(financeHandleWorkflow.getTaskType())){  //提货
			if(financeHandleWorkflow.getPickupId() == null){
				throw new Exception("提货信息ID不能为空！"); 
			} //查询当前节点信息
			PickupApplicationEntity entity = pickupApplicationService.inquirePickupApplication(financeHandleWorkflow.getPickupId());
			PickupAuditInfo pickup = new PickupAuditInfo();
			if(financeHandleWorkflow.getSubmitType().equals("0")){  //保存

				BeanUtils.copyProperties(financeHandleWorkflow, pickup);
				//运营-运营领导-财务-财务领导-风控-风控领导-总经理-执行董事
				if(entity.getFinalState().equals(ApiFinanceStateEnum.YY.getCode())){
					//货物估值信息转换
					if(!StringUtils.isEmpty(financeHandleWorkflow.getEvaluationPriceJson())){
						logger.info("============================" + financeHandleWorkflow.getEvaluationPriceJson());
						JSONArray json = JSONArray.fromObject(financeHandleWorkflow.getEvaluationPriceJson());
						List jsonlist=JSONArray.toList(json,EvaluationPrice.class);
						financeHandleWorkflow.setEvaluationPriceList(jsonlist);

						if(financeHandleWorkflow.getEvaluationPriceList() != null){
							int size=financeHandleWorkflow.getEvaluationPriceList().size();
							Long [] bulkstockIds= new Long[size], exchangeIds = new Long[size];
							BigDecimal [] evaluatePrice = new BigDecimal[size], lowestPrice=new BigDecimal[size], highestPrice = new BigDecimal[size];
							for(int i=0;i<size;i++){
								EvaluationPrice eva=financeHandleWorkflow.getEvaluationPriceList().get(i);
								exchangeIds[i]=eva.getExchangeId();
								bulkstockIds[i]=eva.getBulkstockIds();
								evaluatePrice[i]=eva.getEvaluatePrice();
								lowestPrice[i]=eva.getLowestPrice();
								highestPrice[i]=eva.getHighestPrice();
							}
							pickup.setExchangeIds(exchangeIds);
							pickup.setExchangeId(exchangeIds);
							pickup.setEvaluatePrice(evaluatePrice);
							pickup.setLowestPrice(lowestPrice);
							pickup.setHighestPrice(highestPrice);
						}
					}

					//业务审核意见
					pickup.setBusinessAudit(financeHandleWorkflow.getOpinion());
					pickup.setBusinessAuditState(financeHandleWorkflow.getSubmitState()==1?true:false);
					financeBulkstockPledgeActionApi.supplementPickupBussinessAuditOpinion(pickup);
				}else if(entity.getFinalState().equals(ApiFinanceStateEnum.FMANAGE.getCode())){

					pickup.setAudit1(financeHandleWorkflow.getOpinion());
					pickup.setAuditState1(financeHandleWorkflow.getSubmitState()==1?true:false);
					financeBulkstockPledgeActionApi.supplementPickupAudit1Opinion(pickup);
				}else if(entity.getFinalState().equals(ApiFinanceStateEnum.ZJ.getCode())){

					pickup.setRiskAudit(financeHandleWorkflow.getOpinion());
					pickup.setRiskAuditState(financeHandleWorkflow.getSubmitState()==1?true:false);
					financeBulkstockPledgeActionApi.supplementPickupRiskAuditOpinion(pickup);
				}else if(entity.getFinalState().equals(ApiFinanceStateEnum.ZJMANAGE.getCode())){

					pickup.setRiskMemberAudit(financeHandleWorkflow.getOpinion());
					pickup.setRiskMemberAuditState(financeHandleWorkflow.getSubmitState()==1?true:false);
					financeBulkstockPledgeActionApi.supplementPickupRiskMemberAuditOpinion(pickup);
				}else if(entity.getFinalState().equals(ApiFinanceStateEnum.FK.getCode())){

					pickup.setFinancialAudit(financeHandleWorkflow.getOpinion());
					pickup.setFinancialAuditState(financeHandleWorkflow.getSubmitState()==1?true:false);
					financeBulkstockPledgeActionApi.supplementPickupFinancialAuditOpinion(pickup);
				}else if(entity.getFinalState().equals(ApiFinanceStateEnum.FKMANAGE.getCode())){

					pickup.setOperationAudit(financeHandleWorkflow.getOpinion());
					pickup.setOperationAuditState(financeHandleWorkflow.getSubmitState()==1?true:false);
					financeBulkstockPledgeActionApi.supplementPickupOperationAuditOpinion(pickup);
				}else if(entity.getFinalState().equals(ApiFinanceStateEnum.YW.getCode())){

					pickup.setCeoAudit(financeHandleWorkflow.getOpinion());
					pickup.setCeoAuditState(financeHandleWorkflow.getSubmitState()==1?true:false);
					financeBulkstockPledgeActionApi.supplementPickupCeoAuditOpinion(pickup);
				}else if(entity.getFinalState().equals(ApiFinanceStateEnum.TMANAGE.getCode())){

					pickup.setFinalAudit(financeHandleWorkflow.getOpinion());
					pickup.setFinalAuditState(financeHandleWorkflow.getSubmitState()==1?true:false);
					financeBulkstockPledgeActionApi.supplementPickupFinalAuditOpinion(pickup);
				}else if(entity.getFinalState().equals(ApiFinanceStateEnum.ZXMANAGE.getCode())){

					pickup.setAudit2(financeHandleWorkflow.getOpinion());
					pickup.setAuditState2(financeHandleWorkflow.getSubmitState()==1?true:false);
					financeBulkstockPledgeActionApi.supplementPickupAudit2Opinion(pickup);
				}
			} else if(financeHandleWorkflow.getSubmitType().equals("1")) {  //提交
				PickupAuditInfo params=new PickupAuditInfo();
				params.setPickupId(financeHandleWorkflow.getPickupId());
				//运营-运营领导-财务-财务领导-风控-风控领导-总经理-执行董事
				if(entity.getFinalState().equals(ApiFinanceStateEnum.YY.getCode())){
					params.setBusinessAudit(financeHandleWorkflow.getOpinion());
					params.setBusinessAuditState(financeHandleWorkflow.getSubmitState()==1?true:false);
					params.setDeviceType("提交");
					financeBulkstockPledgeActionApi.submitPickupBussinessAuditOpinion(params);
				}else if(entity.getFinalState().equals(ApiFinanceStateEnum.FMANAGE.getCode())){
					params.setAudit1(financeHandleWorkflow.getOpinion());
					params.setAuditState1(financeHandleWorkflow.getSubmitState()==1?true:false);
					params.setDeviceType("提交");
					financeBulkstockPledgeActionApi.submitPickupAudit1Opinion(params);
				}else if(entity.getFinalState().equals(ApiFinanceStateEnum.ZJ.getCode())){
					params.setRiskAudit(financeHandleWorkflow.getOpinion());
					params.setRiskAuditState(financeHandleWorkflow.getSubmitState()==1?true:false);
					params.setDeviceType("提交");
					financeBulkstockPledgeActionApi.submitPickupRiskAuditOpinion(params);
				}else if(entity.getFinalState().equals(ApiFinanceStateEnum.ZJMANAGE.getCode())){
					params.setRiskMemberAudit(financeHandleWorkflow.getOpinion());
					params.setRiskMemberAuditState(financeHandleWorkflow.getSubmitState()==1?true:false);
					params.setDeviceType("提交");
					financeBulkstockPledgeActionApi.submitPickupRiskMemberAuditOpinion(params);
				}else if(entity.getFinalState().equals(ApiFinanceStateEnum.FK.getCode())){
					params.setFinancialAudit(financeHandleWorkflow.getOpinion());
					params.setFinancialAuditState(financeHandleWorkflow.getSubmitState()==1?true:false);
					params.setDeviceType("提交");
					financeBulkstockPledgeActionApi.submitPickupFinancialAuditOpinion(params);
				}else if(entity.getFinalState().equals(ApiFinanceStateEnum.FKMANAGE.getCode())){
					params.setOperationAudit(financeHandleWorkflow.getOpinion());
					params.setOperationAuditState(financeHandleWorkflow.getSubmitState()==1?true:false);
					params.setDeviceType("提交");
					financeBulkstockPledgeActionApi.submitPickupOperationAuditOpinion(params);
				}else if(entity.getFinalState().equals(ApiFinanceStateEnum.YW.getCode())){
					params.setCeoAudit(financeHandleWorkflow.getOpinion());
					params.setCeoAuditState(financeHandleWorkflow.getSubmitState()==1?true:false);
					params.setDeviceType("提交");
					financeBulkstockPledgeActionApi.submitPickupCeoAuditOpinion(params);
				}else if(entity.getFinalState().equals(ApiFinanceStateEnum.TMANAGE.getCode())){
					params.setFinalAudit(financeHandleWorkflow.getOpinion());
					params.setFinalAuditState(financeHandleWorkflow.getSubmitState()==1?true:false);
					params.setDeviceType("提交");
					financeBulkstockPledgeActionApi.submitPickupFinalAuditOpinion(params);
				}else if(entity.getFinalState().equals(ApiFinanceStateEnum.ZXMANAGE.getCode())){
					params.setAudit2(financeHandleWorkflow.getOpinion());
					params.setAuditState2(financeHandleWorkflow.getSubmitState()==1?true:false);
					params.setDeviceType("提交");
					financeBulkstockPledgeActionApi.submitPickupAudit2Opinion(params);
				}
			}
		}
		return map;
	}

	@Override
	public Map<String, Object> handleWarehousePickupWorkflowInfo(Long pickupId, Boolean auditState, String auditRemark)
			throws Exception {
		PickupApplicationWarehouseEntity pawe = pickupApplicationWarehouseService.inquirePickupApplicationWarehouseDetail(pickupId);
		if(pawe.getFinalState().equals(ApiFinanceStateEnum.SW.getCode())){
			financePickupApplicationWarehouseApi.submitBussinessAuditOpinions(pickupId, auditState, auditRemark);
		} else if(pawe.getFinalState().equals(ApiFinanceStateEnum.YY.getCode())){
			financePickupApplicationWarehouseApi.submitOperateBussinessAuditOpinion(pickupId, auditState, auditRemark);
		} else if(pawe.getFinalState().equals(ApiFinanceStateEnum.FK.getCode())){
			financePickupApplicationWarehouseApi.submitRiskBussinessAuditOpinion(pickupId, auditState, auditRemark);
		} else if(pawe.getFinalState().equals(ApiFinanceStateEnum.ZJ.getCode())){
			financePickupApplicationWarehouseApi.submitFinanceBussinessAuditOpinion(pickupId, auditState, auditRemark);
		} else if(pawe.getFinalState().equals(ApiFinanceStateEnum.ZJMANAGE.getCode())){
			financePickupApplicationWarehouseApi.submitFinanceAdminBussinessAuditOpinion(pickupId, auditState, auditRemark);
		} else if(pawe.getFinalState().equals(ApiFinanceStateEnum.FMANAGE.getCode())){
			financePickupApplicationWarehouseApi.submitViceManagerBussinessAuditOpinion(pickupId, auditState, auditRemark);
		}
		return null;
	}

	@Override
	public List<FinanceEmployeeInfo> addressList() {
		//查询员工头像
		List<FinanceEmployeeInfo> outList=new ArrayList<FinanceEmployeeInfo>();
		List<FinanceEmployeeEntity> list=financeEmployeeService.inquireEmployList();
		for(FinanceEmployeeEntity emp:list){
			FinanceEmployeeInfo info=new FinanceEmployeeInfo();
			BeanUtils.copyProperties(emp, info);

			if(info.getAccountId()!=null){
				//判断用户是否登录
				DetachedCriteria criteria = DetachedCriteria.forClass(AccountSessionEntity.class);
				criteria.add(Restrictions.eq("accountId", info.getAccountId()));
				criteria.add(Restrictions.eq("appUuid", FinanceConstant.APPKEY_PLATFORM_WEB));
				List<AccountSessionEntity> accountList = PersistUtil.get(criteria);
				if (accountList!=null && accountList.size()>0) { //在线
					AccountSessionEntity entity=accountList.get(0);
					String extraJson=entity.getExtra();
					JSONObject jsonObject =  JSONObject.fromObject(extraJson);  

					if(jsonObject.containsKey("isApp") && !StringUtils.isEmpty(jsonObject.getString("isApp"))){
						info.setOnline(1);
					}
				}
			}

			outList.add(info);
		}
		return outList;
	}

	/* (non Javadoc) 
	 * @Title: getOrganizationList
	 * @param departmentId 部门id，不传则获取最高级组织架构
	 * @return 
	 * @see com.yuexunit.finance.project.action.v1.FinanceAppActionApi#getOrganizationList(java.lang.String) 
	 */
	@Override
	public List<FinanceOrganInfo> getOrganizationList() {
		List<FinanceEmployeeInfo> empList=this.getFrequentContactList();  //获取所有联系人列表
		Map<Long,FinanceEmployeeInfo> map=new HashMap<Long,FinanceEmployeeInfo>();
		if(empList!=null){
			for(FinanceEmployeeInfo emp:empList){
				if(!map.containsKey(emp.getId()))map.put(emp.getId(), emp);  //是否常用联系人
			}
		}


		List<FinanceOrganInfo> outList=new ArrayList<FinanceOrganInfo>();
		//查询所有员工信息
		Map<Long,FinanceEmployeeEntity> empMap=new HashMap<Long,FinanceEmployeeEntity>();
		List<FinanceEmployeeEntity> emplist=financeEmployeeService.inquireEmployList();
		for(FinanceEmployeeEntity f:emplist){
			if(!empMap.containsKey(f.getId()))
				empMap.put(f.getId(), f);
		}

		//获取所有员工账号信息
		List<InquireOrganizationTreeOutput> list=organizationActionApi.inquireOrganizationList();
		for(InquireOrganizationTreeOutput dto:list){
			FinanceOrganInfo info=new FinanceOrganInfo();
			//根据企业信息查询，负责人信息
			InquireOrganizationDetailOutput detail=this.inquireOrganizationDetail(dto.getOrganizationId());

			if (detail == null) {
				continue;
			}
			FinanceEmployeeEntity emp=empMap.get(detail.getManagerUserId());
			info.setDirectorId(detail.getManagerUserId());  //员工账号
			info.setDirector(detail.getManagerUserName());
			info.setDirectorAvatar(emp.getPhotoId());    //头像
			info.setDirectorHXAccount(emp.getCurrentArea()); //环信账号
			info.setIsContact(map.get(detail.getManagerUserId())!=null?1:0);//判断是否是常用联系人
			if(empMap.get(detail.getManagerUserId())!=null)
				info.setAccountId(empMap.get(detail.getManagerUserId()).getAccountId());//查询员工账号信息
			List<AccountAlias> accountAlias = accountAction.inquireAccountAliasList(emp.getAccountId());
			info.setDirectorAccount(accountAlias!=null&&accountAlias.size()>0?accountAlias.get(0).getAccountName():"");   //账号
			info.setDepId(dto.getOrganizationId());
			info.setDepName(dto.getName());
			info.setParentId(dto.getParentId());


			PageCriteria page=new PageCriteria(1,Integer.MAX_VALUE-1);
			PageList<EmployeeListDto> pageList=organizationActionApi.inquireEmployeeList("",dto.getOrganizationId(),0,page);
			info.setEmpCount(pageList!=null&&pageList.getTotalRecordCount()!=null?Long.valueOf(pageList.getTotalRecordCount()):0);  //当前员工人数
			//查询员工是否有子节点
			for(InquireOrganizationTreeOutput dto2:list){
				if(dto2.getParentId().equals(dto.getOrganizationId())){
					info.setHaveSubSector(1l);
					break;
				}
			}
			outList.add(info);
		}
		return outList;
	}

	public InquireOrganizationDetailOutput inquireOrganizationDetail(Long orgId)
	{
		logger.info("---organizationId:"+orgId);
		OrganizationEntity org = this.organizationService.inquireOrganization(1l, orgId);
		InquireOrganizationDetailOutput ret = new OrgDetailCastor().getTargetInstance(org);
		if (org == null || ret == null) {
			return null;
		}
		cast(org, ret);
		return ret;
	}

	public void cast(OrganizationEntity f, InquireOrganizationDetailOutput t)
	{
		OrganizationExEntity ex = this.organizationService.inquireOrganizationEx(f.getTenantId(), f.getId());
		t.setOrgId(f.getId());
		t.setName(f.getName());
		if (ex != null) {
			t.setLevel(ex.getLevel());
			t.setTelephone(ex.getTelephone());
		}
		t.setParentOrgId(f.getParentId());
		OrganizationEntity parentEntity = this.organizationService.inquireOrganization(f.getTenantId(), f.getParentId());
		if (parentEntity != null) {
			t.setParentOrgName(parentEntity.getName());
		}
		t.setFax(ex.getFax());
		t.setOnDutyHour(ex.getOnDutyHour());
		t.setCreateDate(f.getCreateDate());
		t.setOrgCode(f.getOrgCode());
		t.setManagerUserId(f.getManagerId());
		EmployeeEntity emp = this.employeeService.inquireEmployee(f.getTenantId(), f.getManagerId());
		if (emp != null)
			t.setManagerUserName(emp.getName());
	}






	@Override
	public List<FinanceEmployeeInfo> getDepartmentMemberList(String departmentId) {
		PageCriteria page=new PageCriteria(1,Integer.MAX_VALUE-1);
		List<Long> list=new ArrayList<Long>();
		if(departmentId!=null)
			list.add(Long.valueOf(departmentId));
		PageList<EmployeeEntity> pages=employeeService.inquireEmployeeList(0l, list, page, "");

		List<FinanceEmployeeInfo> outList=new ArrayList<FinanceEmployeeInfo>();
		for(EmployeeEntity emp:pages){
			FinanceEmployeeInfo info=new FinanceEmployeeInfo();
			BeanUtils.copyProperties(emp, info);
			outList.add(info);
		}
		return outList;
	}

	@Override
	public List<FinanceEmployeeInfo> getFrequentContactList() {
		//查询所有员工信息
		Map<Long,FinanceEmployeeEntity> empMap=new HashMap<Long,FinanceEmployeeEntity>();
		List<FinanceEmployeeEntity> emplist=financeEmployeeService.inquireEmployList();
		for(FinanceEmployeeEntity f:emplist){
			if(!empMap.containsKey(f.getAccountId()))
				empMap.put(f.getAccountId(), f);
		}
		Long accountId=FinanceSessionContext.getAccountId();
		List<FinanceContactsEntity> list=financeContactsService.inquireFinanceContactsList(accountId);
		List<FinanceEmployeeInfo> outList=new ArrayList<FinanceEmployeeInfo>();
		for(FinanceContactsEntity emp:list){
			FinanceEmployeeInfo info=new FinanceEmployeeInfo();
			FinanceEmployeeEntity employee=empMap.get(emp.getContactsId());
			BeanUtils.copyProperties(employee, info);
			if(info.getAccountId()!=null){
				//判断用户是否登录
				DetachedCriteria criteria = DetachedCriteria.forClass(AccountSessionEntity.class);
				criteria.add(Restrictions.eq("accountId", info.getAccountId()));
				criteria.add(Restrictions.eq("appUuid", FinanceConstant.APPKEY_PLATFORM_WEB));
				List<AccountSessionEntity> accountList = PersistUtil.get(criteria);
				if (accountList!=null && accountList.size()>0) { //在线
					AccountSessionEntity entity=accountList.get(0);
					String extraJson=entity.getExtra();
					JSONObject jsonObject =  JSONObject.fromObject(extraJson);  

					if(jsonObject.containsKey("isApp") && !StringUtils.isEmpty(jsonObject.getString("isApp"))){
						info.setOnline(1);
					}
				}
			}
			outList.add(info);
		}
		return outList;
	}

	@Override
	@Transactional
	public void setCommonContact(String contactsId, String type) throws Exception {
		if(contactsId==null)throw new Exception("userId不能为空");
		Long accountId=FinanceSessionContext.getAccountId();
		if(type.equals("1")){//保存
			FinanceContactsEntity entity=new FinanceContactsEntity();
			entity.setAccountId(accountId);
			entity.setContactsId(Long.valueOf(contactsId));
			entity.setCreateDateTime(new Date());
			financeContactsService.createFinanceContactsEntity(entity);
		}else if(type.equals("0")){  //取消
			financeContactsService.deleteFinanceContactsEntity(accountId, Long.valueOf(contactsId));
		}
	}

	@Override
	public List<FinanceEmployeeInfo> inquireEmployeeLists(Long empId) {
		List<FinanceEmployeeEntity> empLists = financeEmployeeService.inquireEmployList();
		Map<Long,Long> empMap=new HashMap<Long,Long>();
		if(empLists!=null && empLists.size()>0){
			for(FinanceEmployeeEntity en:empLists){
				if(en!=null){
					if(!empMap.containsKey(en.getId()))
						empMap.put(en.getId(), en.getAccountId());
				}
			}
		}

		List<FinanceEmployeeInfo> empList=this.getFrequentContactList();  //获取所有联系人列表
		Map<Long,FinanceEmployeeInfo> map=new HashMap<Long,FinanceEmployeeInfo>();
		if(empList!=null){
			for(FinanceEmployeeInfo emp:empList){
				if(!map.containsKey(emp.getId()))map.put(emp.getId(), emp);
			}
		}

		PageCriteria page=new PageCriteria(1,Integer.MAX_VALUE-1);
		PageList<EmployeeListDto> pageList=organizationActionApi.inquireEmployeeList("",empId,0,page);
		List<FinanceEmployeeInfo> outList=new ArrayList<>();
		for(EmployeeListDto dto:pageList){
			FinanceEmployeeInfo info=new FinanceEmployeeInfo();
			BeanUtils.copyProperties(dto, info);
			info.setAccountId(empMap.get(dto.getEmployeeId()));
			info.setId(dto.getEmployeeId());
			info.setIsContact(map.get(info.getId())!=null?1:0);//是否常用联系人0否1是
			if(info.getAccountId()!=null){
				//判断用户是否登录
				DetachedCriteria criteria = DetachedCriteria.forClass(AccountSessionEntity.class);
				criteria.add(Restrictions.eq("accountId", info.getAccountId()));
				criteria.add(Restrictions.eq("appUuid", FinanceConstant.APPKEY_PLATFORM_WEB));
				List<AccountSessionEntity> accountList = PersistUtil.get(criteria);
				if (accountList!=null && accountList.size()>0) { //在线
					AccountSessionEntity entity=accountList.get(0);
					String extraJson=entity.getExtra();
					JSONObject jsonObject =  JSONObject.fromObject(extraJson);  

					if(jsonObject.containsKey("isApp") && !StringUtils.isEmpty(jsonObject.getString("isApp"))){
						info.setOnline(1);
					}
				}
			}
			outList.add(info);
		}

		return outList;
	}

	@Override
	@Transactional
	public void auditEnterpriseSaveByJson(EnterpriseGradeEvaluation params) {
		//认证货物信息 json-转list
		if(params.getFinanceBulkstockPledgeRateJson()!=null){
			JSONArray json = JSONArray.fromObject(params.getFinanceBulkstockPledgeRateJson());
			List<FinanceBulkstockPledgeRateDetail> jsonlist=JSONArray.toList(json,FinanceBulkstockPledgeRateDetail.class);
			params.setFinanceBulkstockPledgeRateList(jsonlist);

			if(params.getFinanceBulkstockPledgeRateList()!=null && params.getFinanceBulkstockPledgeRateList().size()>0){
				int size=params.getFinanceBulkstockPledgeRateList().size();
				String[] productName=new String[size],effectiveStartDates=new String[size],effectiveEndDates=new String[size];
				Integer[] productType=new Integer[size];
				Long[] bulkstockInfoIds=new Long[size];
				BigDecimal[] pledgeRateCeilings=new BigDecimal[size],loanRateCeilings=new BigDecimal[size];

				for(int i=0;i<size;i++){
					FinanceBulkstockPledgeRateDetail rateDetail=params.getFinanceBulkstockPledgeRateList().get(i);
					productName[i]=rateDetail.getProductName();
					effectiveStartDates[i]=rateDetail.getEffectiveStartDate();
					effectiveEndDates[i]=rateDetail.getEffectiveEndDate();
					productType[i]=rateDetail.getProductType();
					bulkstockInfoIds[i]=rateDetail.getBulkstockInfoId();
					pledgeRateCeilings[i]=rateDetail.getPledgeRateCeiling();
					loanRateCeilings[i]=rateDetail.getLoanRateCeiling();
				}
				params.setProductName(productName);
				params.setEffectiveStartDates(effectiveStartDates);
				params.setEffectiveEndDates(effectiveEndDates);
				params.setProductType(productType);
				params.setBulkstockInfoIds(bulkstockInfoIds);
				params.setPledgeRateCeilings(pledgeRateCeilings);
				params.setLoanRateCeilings(loanRateCeilings);
			}
		}

		EnterpriseGradeEvaluationEntity evaluation = EnterpriseCastor.fromEnterpriseGradeEvaluation(params);
		evaluation.setEffectiveStartDate(DateUtil.todayInt());
		evaluation.setAuditState(AuditStateEnum.PASS);
		if (evaluation.getGradeEvaluationId() == null || evaluation.getGradeEvaluationId() == 0L) {
			enterpriseGradeEvaluationService.createEnterpriseGradeEvaluation(evaluation);
		} else {
			enterpriseGradeEvaluationService.updateEnterpriseGradeEvaluation(evaluation);
		}

		EnterpriseGradeEntity grade = enterpriseGradeService.inquireEnterpriseGrade(params.getEnterpriseId());
		if (grade == null) {
			grade = new EnterpriseGradeEntity();
			grade.setEffective(Boolean.FALSE);
			BeanUtils.copyProperties(evaluation, grade);
			grade.setCreditAlready(BigDecimal.ZERO);
			enterpriseGradeService.createEnterpriseGrade(grade);
		} else {
			grade.setEffective(Boolean.FALSE);
			BeanUtils.copyProperties(evaluation, grade);
			grade.setCreditAlready(BigDecimal.ZERO);
			enterpriseGradeService.persistEnterpriseGrade(grade);
		}

		if (params.getBulkstockInfoIds() != null) {
			for(int i = 0; i < params.getBulkstockInfoIds().length; i++) {
				FinanceBulkstockPledgeRateEntity exist = financeBulkstockPledgeRateService.inquireFinanceBulkstockPledgeRate(evaluation.getGradeEvaluationId(), params.getBulkstockInfoIds()[i], ProductTypeEnum.valueOf(params.getProductType()[i]));
				BulkstockInfoEntity bie = bulkstockInfoService.inquireBulkstockInfo(params.getBulkstockInfoIds()[i]);
				if (exist != null) {
					throw new BusinessException("货物" + bie.getBulkstockName() + "(" + bie.getSpecificationName() + ")" + "在有效期内已设置过质押率！");
				}
				FinanceBulkstockPledgeRateEntity entity = new FinanceBulkstockPledgeRateEntity();
				entity.setGradeEvaluationId(evaluation.getGradeEvaluationId());
				entity.setBulkstockInfoId(params.getBulkstockInfoIds()[i]);
				entity.setPledgeRateCeiling(params.getPledgeRateCeilings()[i]);
				entity.setLoanRateCeiling(params.getLoanRateCeilings()[i]);
				entity.setEffectiveEndDate(DateUtil.parseDateInt(params.getEffectiveEndDates()[i]));
				entity.setEffectiveStartDate(DateUtil.parseDateInt(params.getEffectiveStartDates()[i]));
				entity.setProductName(params.getProductName()[i]);
				entity.setProductType(ProductTypeEnum.valueOf(params.getProductType()[i]));
				financeBulkstockPledgeRateService.createFinanceBulkstockPledgeRate(entity);
			}
		}
	}




	@Override
	@Transactional
	public Map<String,Object> handleEnterpriseAudit(Long enterpriseId, String taskType,
			String submitType, Long submitState, String opinion) throws Exception {
		Map<String,Object> map=new HashMap<String,Object>();
		if(enterpriseId==null){throw new Exception("企业ID不能为空！"); } //查询当前节点信息
		EnterpriseEntity entity = enterpriseService.inquireEnterprise(enterpriseId);

		//获取当前登入用户角色
		Long accountId=FinanceSessionContext.getAccountId();
		List<RoleListDto> rl = permissionAction.inquireAccountRoleList(accountId); 

		if(submitType.equals("0")){  //保存
			if(entity==null){throw new Exception("企业信息不存在！"); }
			//市场--》风控--》总经理---》18:复核风控--》16:复核市场 && 财务         -->17:复核市场  -->9:财务
			//市场--》业务总监--》业务副总--风控--》风控领导--》副总经理--》总经理--》18:复核风控--》16:复核市场 && 财务 &&运营        -->17:复核市场  -->9:财务-->运营
			switch (entity.getFinalState().intValue()) {
			case 1:
				enterpriseActionApi.saveEnterpriseAudit(enterpriseId,1,submitState==1?true:false,opinion,"");
				break;
			case 19:
				enterpriseActionApi.saveEnterpriseAudit(enterpriseId,7,submitState==1?true:false,opinion,"");
				break;
			case 21:
				enterpriseActionApi.saveEnterpriseAudit(enterpriseId,8,submitState==1?true:false,opinion,"");
				break;
			case 3:
				enterpriseActionApi.saveEnterpriseAudit(enterpriseId,2,submitState==1?true:false,opinion,"");
				break;
			case 4:
				enterpriseActionApi.saveEnterpriseAudit(enterpriseId,9,submitState==1?true:false,opinion,"");
				break;
			case 20:
				enterpriseActionApi.saveEnterpriseAudit(enterpriseId,10,submitState==1?true:false,opinion,"");
				break;
			case 12:
				enterpriseActionApi.saveEnterpriseAudit(enterpriseId,3,submitState==1?true:false,opinion,"");
				break;
			case 18:
				enterpriseActionApi.saveEnterpriseAudit(enterpriseId,4,submitState==1?true:false,opinion,"");
				break;
			case 11://董事长
				enterpriseActionApi.saveEnterpriseAudit(enterpriseId,12,submitState==1?true:false,opinion,"");
				break;
			case 22:
				//根据当前登入系统角色区分 复核市场 市场  || 财务 || 运营
				if(taskCheckInfo(rl,ApiFinanceStateEnum.RYW.getCode())){  //角色复核市场
					enterpriseActionApi.saveEnterpriseAudit(enterpriseId,5,submitState==1?true:false,opinion,"");
				}else if(taskCheckInfo(rl,ApiFinanceStateEnum.ZJ.getCode())){  //财务
					enterpriseActionApi.saveEnterpriseAudit(enterpriseId,6,submitState==1?true:false,opinion,"");
				}else if(taskCheckInfo(rl,ApiFinanceStateEnum.YY.getCode())){  //财务
					enterpriseActionApi.saveEnterpriseAudit(enterpriseId,11,submitState==1?true:false,opinion,"");
				}
				break;
			case 16:
				//根据当前登入系统角色区分 复核市场 市场  || 财务
				if(taskCheckInfo(rl,ApiFinanceStateEnum.RYW.getCode())){  //角色复核市场
					enterpriseActionApi.saveEnterpriseAudit(enterpriseId,5,submitState==1?true:false,opinion,"");
				}else if(taskCheckInfo(rl,ApiFinanceStateEnum.ZJ.getCode())){  //财务
					enterpriseActionApi.saveEnterpriseAudit(enterpriseId,6,submitState==1?true:false,opinion,"");
				}
				break;
			case 23:
				//根据当前登入系统角色区分 复核市场 市场  || 运营
				if(taskCheckInfo(rl,ApiFinanceStateEnum.RYW.getCode())){  //角色复核市场
					enterpriseActionApi.saveEnterpriseAudit(enterpriseId,5,submitState==1?true:false,opinion,"");
				}else if(taskCheckInfo(rl,ApiFinanceStateEnum.YY.getCode())){  //运营
					enterpriseActionApi.saveEnterpriseAudit(enterpriseId,11,submitState==1?true:false,opinion,"");
				}
				break;
			case 24:
				//根据当前登入系统角色区分 复核市场 财务  || 运营
				if(taskCheckInfo(rl,ApiFinanceStateEnum.ZJ.getCode())){  //财务
					enterpriseActionApi.saveEnterpriseAudit(enterpriseId,6,submitState==1?true:false,opinion,"");
				}else if(taskCheckInfo(rl,ApiFinanceStateEnum.YY.getCode())){  //运营
					enterpriseActionApi.saveEnterpriseAudit(enterpriseId,11,submitState==1?true:false,opinion,"");
				}
				break;
			case 17:
				enterpriseActionApi.saveEnterpriseAudit(enterpriseId,5,submitState==1?true:false,opinion,""); 
				break;
			case 9:
				enterpriseActionApi.saveEnterpriseAudit(enterpriseId,6,submitState==1?true:false,opinion,"");
				break;
			case 5:
				enterpriseActionApi.saveEnterpriseAudit(enterpriseId,11,submitState==1?true:false,opinion,"");
				break;
			default:
				break;
			}
		}else if(submitType.equals("1")){   //提交
			switch (entity.getFinalState().intValue()) {
			case 1:
				enterpriseActionApi.submitEnterpriseAudit(enterpriseId,1,submitState==1?true:false,opinion,"");
				break;
			case 19:
				enterpriseActionApi.submitEnterpriseAudit(enterpriseId,7,submitState==1?true:false,opinion,"");
				break;
			case 21:
				enterpriseActionApi.submitEnterpriseAudit(enterpriseId,8,submitState==1?true:false,opinion,"");
				break;
			case 3:
				enterpriseActionApi.submitEnterpriseAudit(enterpriseId,2,submitState==1?true:false,opinion,"");
				break;
			case 4:
				enterpriseActionApi.submitEnterpriseAudit(enterpriseId,9,submitState==1?true:false,opinion,"");
				break;
			case 20:
				enterpriseActionApi.submitEnterpriseAudit(enterpriseId,10,submitState==1?true:false,opinion,"");
				break;
			case 12:
				enterpriseActionApi.submitEnterpriseAudit(enterpriseId,3,submitState==1?true:false,opinion,"");
				break;
			case 18:
				enterpriseActionApi.submitEnterpriseAudit(enterpriseId,4,submitState==1?true:false,opinion,"");
				break;
			case 11:
				enterpriseActionApi.submitEnterpriseAudit(enterpriseId,12,submitState==1?true:false,opinion,"");
				break;
			case 22:
				//根据当前登入系统角色区分 复核市场 市场  || 财务 ||运营
				if(taskCheckInfo(rl,ApiFinanceStateEnum.RYW.getCode())){  //角色复核市场
					enterpriseActionApi.submitEnterpriseAudit(enterpriseId,5,submitState==1?true:false,opinion,"");
				}else if(taskCheckInfo(rl,ApiFinanceStateEnum.ZJ.getCode())){  //财务
					enterpriseActionApi.submitEnterpriseAudit(enterpriseId,6,submitState==1?true:false,opinion,"");
				}else if(taskCheckInfo(rl,ApiFinanceStateEnum.YY.getCode())){  //财务
					enterpriseActionApi.submitEnterpriseAudit(enterpriseId,11,submitState==1?true:false,opinion,"");
				}
				break;
			case 16:
				//根据当前登入系统角色区分 复核市场 市场  || 财务
				if(taskCheckInfo(rl,ApiFinanceStateEnum.RYW.getCode())){  //角色复核市场
					enterpriseActionApi.submitEnterpriseAudit(enterpriseId,5,submitState==1?true:false,opinion,"");
				}else if(taskCheckInfo(rl,ApiFinanceStateEnum.ZJ.getCode())){  //财务
					enterpriseActionApi.submitEnterpriseAudit(enterpriseId,6,submitState==1?true:false,opinion,"");
				}
				break;
			case 23:
				//根据当前登入系统角色区分 复核市场 市场  || 运营
				if(taskCheckInfo(rl,ApiFinanceStateEnum.RYW.getCode())){  //角色复核市场
					enterpriseActionApi.submitEnterpriseAudit(enterpriseId,5,submitState==1?true:false,opinion,"");
				}else if(taskCheckInfo(rl,ApiFinanceStateEnum.YY.getCode())){  //财务
					enterpriseActionApi.submitEnterpriseAudit(enterpriseId,11,submitState==1?true:false,opinion,"");
				}
				break;
			case 24:
				//根据当前登入系统角色区分 复核市场 运营  || 财务
				if(taskCheckInfo(rl,ApiFinanceStateEnum.ZJ.getCode())){  //财务
					enterpriseActionApi.submitEnterpriseAudit(enterpriseId,6,submitState==1?true:false,opinion,"");
				}else if(taskCheckInfo(rl,ApiFinanceStateEnum.YY.getCode())){  //财务
					enterpriseActionApi.submitEnterpriseAudit(enterpriseId,11,submitState==1?true:false,opinion,"");
				}
				break;
			case 17:
				enterpriseActionApi.submitEnterpriseAudit(enterpriseId,5,submitState==1?true:false,opinion,"");
				break;
			case 9:
				enterpriseActionApi.submitEnterpriseAudit(enterpriseId,6,submitState==1?true:false,opinion,"");
				break;
			case 5:
				enterpriseActionApi.submitEnterpriseAudit(enterpriseId,11,submitState==1?true:false,opinion,"");
				break;
			default:
				break;
			}
		}

		return map;
	}

	@Override
	@Transactional
	public Map<String, Object> handleEnterpriseGradeAudit(
			Long gradeEvaluationId, String taskType, String submitType,
			Long submitState, String opinion) throws Exception {
		Map<String,Object> map=new HashMap<String,Object>();
		if(gradeEvaluationId==null){throw new Exception("会员评估等级ID不能为空！"); } //查询当前节点信息
		EnterpriseGradeEvaluationEntity entity = enterpriseGradeEvaluationService.inquireEnterpriseGradeEvaluationDetail(gradeEvaluationId);

		//获取当前登入用户角色
		Long accountId=FinanceSessionContext.getAccountId();
		List<RoleListDto> rl = permissionAction.inquireAccountRoleList(accountId);  

		if(submitType.equals("0")){  //保存
			if(entity==null){throw new Exception("会员评估等级信息不存在！"); }
			switch (entity.getFinalState().intValue()) {
			case 1:
				enterpriseActionApi.saveEnterpriseGradeAudit(gradeEvaluationId,1,submitState==1?true:false,opinion,"");
				break;
			case 19:
				enterpriseActionApi.saveEnterpriseGradeAudit(gradeEvaluationId,7,submitState==1?true:false,opinion,"");
				break;
			case 21:
				enterpriseActionApi.saveEnterpriseGradeAudit(gradeEvaluationId,8,submitState==1?true:false,opinion,"");
				break;
			case 3:
				enterpriseActionApi.saveEnterpriseGradeAudit(gradeEvaluationId,2,submitState==1?true:false,opinion,"");
				break;
			case 4:
				enterpriseActionApi.saveEnterpriseGradeAudit(gradeEvaluationId,9,submitState==1?true:false,opinion,"");
				break;
			case 20:
				enterpriseActionApi.saveEnterpriseGradeAudit(gradeEvaluationId,10,submitState==1?true:false,opinion,"");
				break;
			case 12:
				enterpriseActionApi.saveEnterpriseGradeAudit(gradeEvaluationId,3,submitState==1?true:false,opinion,"");
				break;
			case 18:
				enterpriseActionApi.saveEnterpriseGradeAudit(gradeEvaluationId,4,submitState==1?true:false,opinion,"");
				break;
			case 11:
				enterpriseActionApi.saveEnterpriseGradeAudit(gradeEvaluationId,12,submitState==1?true:false,opinion,"");
				break;
			case 22:
				//根据当前登入系统角色区分 复核市场 市场  || 财务 || 运营
				if(taskCheckInfo(rl,ApiFinanceStateEnum.RYW.getCode())){  //角色复核市场
					enterpriseActionApi.saveEnterpriseGradeAudit(gradeEvaluationId,5,submitState==1?true:false,opinion,"");
				}else if(taskCheckInfo(rl,ApiFinanceStateEnum.ZJ.getCode())){  //财务
					enterpriseActionApi.saveEnterpriseGradeAudit(gradeEvaluationId,6,submitState==1?true:false,opinion,"");
				}else if(taskCheckInfo(rl,ApiFinanceStateEnum.YY.getCode())){  //运营
					enterpriseActionApi.saveEnterpriseGradeAudit(gradeEvaluationId,11,submitState==1?true:false,opinion,"");
				}
				break;
			case 16:
				//根据当前登入系统角色区分 复核市场 市场  || 财务
				if(taskCheckInfo(rl,ApiFinanceStateEnum.RYW.getCode())){  //角色复核市场
					enterpriseActionApi.saveEnterpriseGradeAudit(gradeEvaluationId,5,submitState==1?true:false,opinion,"");
				}else if(taskCheckInfo(rl,ApiFinanceStateEnum.ZJ.getCode())){  //财务
					enterpriseActionApi.saveEnterpriseGradeAudit(gradeEvaluationId,6,submitState==1?true:false,opinion,"");
				}
				break;
			case 23:
				//根据当前登入系统角色区分 复核市场 市场  || 运营
				if(taskCheckInfo(rl,ApiFinanceStateEnum.RYW.getCode())){  //角色复核市场
					enterpriseActionApi.saveEnterpriseGradeAudit(gradeEvaluationId,5,submitState==1?true:false,opinion,"");
				}else if(taskCheckInfo(rl,ApiFinanceStateEnum.YY.getCode())){  //运营
					enterpriseActionApi.saveEnterpriseGradeAudit(gradeEvaluationId,11,submitState==1?true:false,opinion,"");
				}
				break;
			case 24:
				//根据当前登入系统角色区分 复核市场 运营  || 财务
				if(taskCheckInfo(rl,ApiFinanceStateEnum.ZJ.getCode())){  //财务
					enterpriseActionApi.saveEnterpriseGradeAudit(gradeEvaluationId,6,submitState==1?true:false,opinion,"");
				}else if(taskCheckInfo(rl,ApiFinanceStateEnum.YY.getCode())){  //运营
					enterpriseActionApi.saveEnterpriseGradeAudit(gradeEvaluationId,11,submitState==1?true:false,opinion,"");
				}
				break;
			case 17:
				enterpriseActionApi.saveEnterpriseGradeAudit(gradeEvaluationId,5,submitState==1?true:false,opinion,"");
				break;
			case 9:
				enterpriseActionApi.saveEnterpriseGradeAudit(gradeEvaluationId,6,submitState==1?true:false,opinion,"");
				break;
			case 5:
				enterpriseActionApi.saveEnterpriseGradeAudit(gradeEvaluationId,11,submitState==1?true:false,opinion,"");
				break;
			default:
				break;
			}
		}else if(submitType.equals("1")){   //提交
			switch (entity.getFinalState().intValue()) {
			case 1:
				enterpriseActionApi.submitEnterpriseGradeAudit(gradeEvaluationId,1,submitState==1?true:false,opinion,"");
				break;
			case 19:
				enterpriseActionApi.submitEnterpriseGradeAudit(gradeEvaluationId,7,submitState==1?true:false,opinion,"");
				break;
			case 21:
				enterpriseActionApi.submitEnterpriseGradeAudit(gradeEvaluationId,8,submitState==1?true:false,opinion,"");
				break;
			case 3:
				enterpriseActionApi.submitEnterpriseGradeAudit(gradeEvaluationId,2,submitState==1?true:false,opinion,"");
				break;
			case 4:
				enterpriseActionApi.submitEnterpriseGradeAudit(gradeEvaluationId,9,submitState==1?true:false,opinion,"");
				break;
			case 20:
				enterpriseActionApi.submitEnterpriseGradeAudit(gradeEvaluationId,10,submitState==1?true:false,opinion,"");
				break;
			case 12:
				enterpriseActionApi.submitEnterpriseGradeAudit(gradeEvaluationId,3,submitState==1?true:false,opinion,"");
				break;
			case 11:
				enterpriseActionApi.submitEnterpriseGradeAudit(gradeEvaluationId,12,submitState==1?true:false,opinion,"");
				break;
			case 18:
				enterpriseActionApi.submitEnterpriseGradeAudit(gradeEvaluationId,4,submitState==1?true:false,opinion,"");
				break;
			case 22:
				//根据当前登入系统角色区分 复核市场 市场  || 财务 || 运营
				if(taskCheckInfo(rl,ApiFinanceStateEnum.RYW.getCode())){  //角色复核市场
					enterpriseActionApi.submitEnterpriseGradeAudit(gradeEvaluationId,5,submitState==1?true:false,opinion,"");
				}else if(taskCheckInfo(rl,ApiFinanceStateEnum.ZJ.getCode())){  //财务
					enterpriseActionApi.submitEnterpriseGradeAudit(gradeEvaluationId,6,submitState==1?true:false,opinion,"");
				}else if(taskCheckInfo(rl,ApiFinanceStateEnum.YY.getCode())){  //运营
					enterpriseActionApi.submitEnterpriseGradeAudit(gradeEvaluationId,11,submitState==1?true:false,opinion,"");
				}
				break;
			case 16:
				//根据当前登入系统角色区分 复核市场 市场  || 财务
				if(taskCheckInfo(rl,ApiFinanceStateEnum.RYW.getCode())){  //角色复核市场
					enterpriseActionApi.submitEnterpriseGradeAudit(gradeEvaluationId,5,submitState==1?true:false,opinion,"");
				}else if(taskCheckInfo(rl,ApiFinanceStateEnum.ZJ.getCode())){  //财务
					enterpriseActionApi.submitEnterpriseGradeAudit(gradeEvaluationId,6,submitState==1?true:false,opinion,"");
				}
				break;
			case 23:
				//根据当前登入系统角色区分 复核市场 市场  || 运营
				if(taskCheckInfo(rl,ApiFinanceStateEnum.RYW.getCode())){  //角色复核市场
					enterpriseActionApi.submitEnterpriseGradeAudit(gradeEvaluationId,5,submitState==1?true:false,opinion,"");
				}else if(taskCheckInfo(rl,ApiFinanceStateEnum.YY.getCode())){  //运营
					enterpriseActionApi.submitEnterpriseGradeAudit(gradeEvaluationId,11,submitState==1?true:false,opinion,"");
				}
				break;
			case 24:
				//根据当前登入系统角色区分 复核市场 运营  || 财务
				if(taskCheckInfo(rl,ApiFinanceStateEnum.ZJ.getCode())){  //财务
					enterpriseActionApi.submitEnterpriseGradeAudit(gradeEvaluationId,6,submitState==1?true:false,opinion,"");
				}else if(taskCheckInfo(rl,ApiFinanceStateEnum.YY.getCode())){  //运营
					enterpriseActionApi.submitEnterpriseGradeAudit(gradeEvaluationId,11,submitState==1?true:false,opinion,"");
				}
				break;
			case 17:
				enterpriseActionApi.submitEnterpriseGradeAudit(gradeEvaluationId,5,submitState==1?true:false,opinion,"");
				break;
			case 9:
				enterpriseActionApi.submitEnterpriseGradeAudit(gradeEvaluationId,6,submitState==1?true:false,opinion,"");
				break;
			case 5:
				enterpriseActionApi.submitEnterpriseGradeAudit(gradeEvaluationId,11,submitState==1?true:false,opinion,"");
				break;
			default:
				break;
			}
		}
		return map;
	}	

	@Override
	@Transactional
	public Map<String, Object> handleEnterpriseTemQuotaAudit(
			Long temporaryCreditlineEvaluationId, String taskType,
			String submitType, Long submitState, String opinion)
					throws Exception {
		Map<String,Object> map=new HashMap<String,Object>();
		if(temporaryCreditlineEvaluationId==null){throw new Exception("临时额度调整ID不能为空！"); } //查询当前节点信息
		TemporaryCreditlineEvaluationEntity entity = temporaryCreditlineEvaluationService.inquireTemporaryCreDitlineEvaluation(temporaryCreditlineEvaluationId);

		//获取当前登入用户角色
		Long accountId=FinanceSessionContext.getAccountId();
		List<RoleListDto> rl = permissionAction.inquireAccountRoleList(accountId);

		if(submitType.equals("0")){  //保存
			if(entity==null){throw new Exception("临时额度调整信息不存在！"); }
			switch (entity.getFinalState().intValue()) {
			case 1:
				enterpriseActionApi.saveTemporaryCreditlineEvaluation(temporaryCreditlineEvaluationId,1,submitState==1?true:false,opinion,"");
				break;
			case 19:
				enterpriseActionApi.saveTemporaryCreditlineEvaluation(temporaryCreditlineEvaluationId,7,submitState==1?true:false,opinion,"");
				break;
			case 21:
				enterpriseActionApi.saveTemporaryCreditlineEvaluation(temporaryCreditlineEvaluationId,8,submitState==1?true:false,opinion,"");
				break;
			case 3:
				enterpriseActionApi.saveTemporaryCreditlineEvaluation(temporaryCreditlineEvaluationId,2,submitState==1?true:false,opinion,"");
				break;
			case 4:
				enterpriseActionApi.saveTemporaryCreditlineEvaluation(temporaryCreditlineEvaluationId,9,submitState==1?true:false,opinion,"");
				break;
			case 20:
				enterpriseActionApi.saveTemporaryCreditlineEvaluation(temporaryCreditlineEvaluationId,10,submitState==1?true:false,opinion,"");
				break;
			case 12:
				enterpriseActionApi.saveTemporaryCreditlineEvaluation(temporaryCreditlineEvaluationId,3,submitState==1?true:false,opinion,"");
				break;
			case 18:
				enterpriseActionApi.saveTemporaryCreditlineEvaluation(temporaryCreditlineEvaluationId,4,submitState==1?true:false,opinion,"");
				break;
			case 22:
				//根据当前登入系统角色区分 复核市场 市场  || 财务 || 运营
				if(taskCheckInfo(rl,ApiFinanceStateEnum.RYW.getCode())){  //角色复核市场
					enterpriseActionApi.saveTemporaryCreditlineEvaluation(temporaryCreditlineEvaluationId,5,submitState==1?true:false,opinion,"");
				}else if(taskCheckInfo(rl,ApiFinanceStateEnum.ZJ.getCode())){  //财务
					enterpriseActionApi.saveTemporaryCreditlineEvaluation(temporaryCreditlineEvaluationId,6,submitState==1?true:false,opinion,"");
				}else if(taskCheckInfo(rl,ApiFinanceStateEnum.YY.getCode())){  //运营
					enterpriseActionApi.saveTemporaryCreditlineEvaluation(temporaryCreditlineEvaluationId,11,submitState==1?true:false,opinion,"");
				}
				break;
			case 16:
				//根据当前登入系统角色区分 复核市场 市场  || 财务
				if(taskCheckInfo(rl,ApiFinanceStateEnum.RYW.getCode())){  //角色复核市场
					enterpriseActionApi.saveTemporaryCreditlineEvaluation(temporaryCreditlineEvaluationId,5,submitState==1?true:false,opinion,"");
				}else if(taskCheckInfo(rl,ApiFinanceStateEnum.ZJ.getCode())){  //财务
					enterpriseActionApi.saveTemporaryCreditlineEvaluation(temporaryCreditlineEvaluationId,6,submitState==1?true:false,opinion,"");
				}
				break;
			case 23:
				//根据当前登入系统角色区分 复核市场 市场 || 运营
				if(taskCheckInfo(rl,ApiFinanceStateEnum.RYW.getCode())){  //角色复核市场
					enterpriseActionApi.saveTemporaryCreditlineEvaluation(temporaryCreditlineEvaluationId,5,submitState==1?true:false,opinion,"");
				}else if(taskCheckInfo(rl,ApiFinanceStateEnum.YY.getCode())){  //财务
					enterpriseActionApi.saveTemporaryCreditlineEvaluation(temporaryCreditlineEvaluationId,11,submitState==1?true:false,opinion,"");
				}
				break;
			case 24:
				//根据当前登入系统角色区分 复核市场  财务 || 运营
				if(taskCheckInfo(rl,ApiFinanceStateEnum.ZJ.getCode())){  //财务
					enterpriseActionApi.saveTemporaryCreditlineEvaluation(temporaryCreditlineEvaluationId,6,submitState==1?true:false,opinion,"");
				}else if(taskCheckInfo(rl,ApiFinanceStateEnum.YY.getCode())){  //财务
					enterpriseActionApi.saveTemporaryCreditlineEvaluation(temporaryCreditlineEvaluationId,11,submitState==1?true:false,opinion,"");
				}
				break;
			case 17:
				enterpriseActionApi.saveTemporaryCreditlineEvaluation(temporaryCreditlineEvaluationId,5,submitState==1?true:false,opinion,"");
				break;
			case 9:
				enterpriseActionApi.saveTemporaryCreditlineEvaluation(temporaryCreditlineEvaluationId,6,submitState==1?true:false,opinion,"");
				break;
			case 5:
				enterpriseActionApi.saveTemporaryCreditlineEvaluation(temporaryCreditlineEvaluationId,11,submitState==1?true:false,opinion,"");
				break;
			default:
				break;
			}
		}else if(submitType.equals("1")){   //提交
			switch (entity.getFinalState().intValue()) {
			case 1:
				enterpriseActionApi.submitTemporaryCreditlineEvaluation(temporaryCreditlineEvaluationId,1,submitState==1?true:false,opinion,"");
				break;
			case 19:
				enterpriseActionApi.submitTemporaryCreditlineEvaluation(temporaryCreditlineEvaluationId,7,submitState==1?true:false,opinion,"");
				break;
			case 21:
				enterpriseActionApi.submitTemporaryCreditlineEvaluation(temporaryCreditlineEvaluationId,8,submitState==1?true:false,opinion,"");
				break;
			case 3:
				enterpriseActionApi.submitTemporaryCreditlineEvaluation(temporaryCreditlineEvaluationId,2,submitState==1?true:false,opinion,"");
				break;
			case 4:
				enterpriseActionApi.submitTemporaryCreditlineEvaluation(temporaryCreditlineEvaluationId,9,submitState==1?true:false,opinion,"");
				break;
			case 20:
				enterpriseActionApi.submitTemporaryCreditlineEvaluation(temporaryCreditlineEvaluationId,10,submitState==1?true:false,opinion,"");
				break;
			case 12:
				enterpriseActionApi.submitTemporaryCreditlineEvaluation(temporaryCreditlineEvaluationId,3,submitState==1?true:false,opinion,"");
				break;
			case 18:
				enterpriseActionApi.submitTemporaryCreditlineEvaluation(temporaryCreditlineEvaluationId,4,submitState==1?true:false,opinion,"");
				break;
			case 22:
				//根据当前登入系统角色区分 复核市场 市场  || 财务 || 运营
				if(taskCheckInfo(rl,ApiFinanceStateEnum.RYW.getCode())){  //角色复核市场
					enterpriseActionApi.submitTemporaryCreditlineEvaluation(temporaryCreditlineEvaluationId,5,submitState==1?true:false,opinion,"");
				}else if(taskCheckInfo(rl,ApiFinanceStateEnum.ZJ.getCode())){  //财务
					enterpriseActionApi.submitTemporaryCreditlineEvaluation(temporaryCreditlineEvaluationId,6,submitState==1?true:false,opinion,"");
				}else if(taskCheckInfo(rl,ApiFinanceStateEnum.YY.getCode())){  //财务
					enterpriseActionApi.submitTemporaryCreditlineEvaluation(temporaryCreditlineEvaluationId,11,submitState==1?true:false,opinion,"");
				}
				break;
			case 16:
				//根据当前登入系统角色区分 复核市场 市场  || 财务
				if(taskCheckInfo(rl,ApiFinanceStateEnum.RYW.getCode())){  //角色复核市场
					enterpriseActionApi.submitTemporaryCreditlineEvaluation(temporaryCreditlineEvaluationId,5,submitState==1?true:false,opinion,"");
				}else if(taskCheckInfo(rl,ApiFinanceStateEnum.ZJ.getCode())){  //财务
					enterpriseActionApi.submitTemporaryCreditlineEvaluation(temporaryCreditlineEvaluationId,6,submitState==1?true:false,opinion,"");
				}
				break;
			case 23:
				//根据当前登入系统角色区分 复核市场 市场  || 运营
				if(taskCheckInfo(rl,ApiFinanceStateEnum.RYW.getCode())){  //角色复核市场
					enterpriseActionApi.submitTemporaryCreditlineEvaluation(temporaryCreditlineEvaluationId,5,submitState==1?true:false,opinion,"");
				}else if(taskCheckInfo(rl,ApiFinanceStateEnum.YY.getCode())){  //财务
					enterpriseActionApi.submitTemporaryCreditlineEvaluation(temporaryCreditlineEvaluationId,11,submitState==1?true:false,opinion,"");
				}
				break;
			case 24:
				//根据当前登入系统角色区分 复核市场 运营  || 财务
				if(taskCheckInfo(rl,ApiFinanceStateEnum.ZJ.getCode())){  //财务
					enterpriseActionApi.submitTemporaryCreditlineEvaluation(temporaryCreditlineEvaluationId,6,submitState==1?true:false,opinion,"");
				}else if(taskCheckInfo(rl,ApiFinanceStateEnum.YY.getCode())){  //财务
					enterpriseActionApi.submitTemporaryCreditlineEvaluation(temporaryCreditlineEvaluationId,11,submitState==1?true:false,opinion,"");
				}
				break;
			case 17:
				enterpriseActionApi.submitTemporaryCreditlineEvaluation(temporaryCreditlineEvaluationId,5,submitState==1?true:false,opinion,"");
				break;
			case 9:
				enterpriseActionApi.submitTemporaryCreditlineEvaluation(temporaryCreditlineEvaluationId,6,submitState==1?true:false,opinion,"");
				break;
			case 5:
				enterpriseActionApi.submitTemporaryCreditlineEvaluation(temporaryCreditlineEvaluationId,11,submitState==1?true:false,opinion,"");
				break;
			default:
				break;
			}
		}

		return map;
	}

	@Override
	@Transactional
	public Long createFinanceGroupEntity(FinanceGroupInfo financeGroupEntity) {
		FinanceGroupEntity dto=new FinanceGroupEntity();
		BeanUtils.copyProperties(financeGroupEntity, dto);
		dto.setCreateDate(new Date());
		return financeGroupService.createFinanceGroupEntity(dto);
	}

	@Override
	@Transactional
	public void createFinanceGroupMemberEntity(String groupId,String groupName,String emps) {
		String [] arr=emps.split(",");
		if(arr!=null && arr.length>0){
			for(int i =0;i<arr.length;i++){
				FinanceGroupMemberEntity dto=new FinanceGroupMemberEntity();
				dto.setGroupId(groupId);
				FinanceEmployeeEntity financeEmployeeEntity=financeEmployeeService.inquireEmployee(Long.valueOf(arr[i]));
				if(financeEmployeeEntity!=null){
					dto.setHxAccount(financeEmployeeEntity.getCurrentArea());
					dto.setName(financeEmployeeEntity.getName());
					dto.setPhotoId(financeEmployeeEntity.getPhotoId());
					dto.setEmpId(financeEmployeeEntity.getId());
				}
				dto.setCreateDateTime(new Date());
				financeGroupService.createFinanceGroupMemberEntity(dto);
			}
		}
	}

	@Override
	public List<FinanceGroupInfo> inquireFinanceGroupEntityList() {
		List<FinanceGroupInfo> outlist=new ArrayList<>();
		List<FinanceGroupEntity> list=financeGroupService.inquireFinanceGroupEntityList();
		for(FinanceGroupEntity financeGroupEntity:list){
			FinanceGroupInfo dto=new FinanceGroupInfo();
			BeanUtils.copyProperties(financeGroupEntity, dto);
			outlist.add(dto);
		}
		return outlist;
	}

	@Override
	public List<FinanceGroupMemberInfo> inquireFinanceGroupMemberEntityList(
			String groupId) {
		List<FinanceGroupMemberInfo> outlist=new ArrayList<FinanceGroupMemberInfo>();
		List<FinanceGroupMemberEntity> list=financeGroupService.inquireFinanceGroupMemberEntityList(groupId);
		for(FinanceGroupMemberEntity bean:list){
			FinanceGroupMemberInfo dto=new FinanceGroupMemberInfo();
			BeanUtils.copyProperties(bean, dto);
			outlist.add(dto);
		}
		return outlist;
	}

	@Override
	@Transactional
	public void deleteFinanceGroupMember(Long emp, String groupId) {
		financeGroupService.deleteFinanceGroupMember(emp, groupId);
	}

	@Override
	@Transactional
	public void deleteFinanceGroup(String groupId) {
		financeGroupService.deleteFinanceGroup(groupId);
	}

	@Override
	public List<FinanceEmployeeInfo> inquireEmployeeLikeList(String name) {
		//查询所有员工信息
		List<FinanceEmployeeEntity> emplist=financeEmployeeService.inquireEmployLikeList(name);
		List<FinanceEmployeeInfo> outList=new ArrayList<FinanceEmployeeInfo>();
		for(FinanceEmployeeEntity emp:emplist){
			FinanceEmployeeInfo info=new FinanceEmployeeInfo();
			BeanUtils.copyProperties(emp, info);
			if(info.getAccountId()!=null){
				//判断用户是否登录
				DetachedCriteria criteria = DetachedCriteria.forClass(AccountSessionEntity.class);
				criteria.add(Restrictions.eq("accountId", info.getAccountId()));
				criteria.add(Restrictions.eq("appUuid", FinanceConstant.APPKEY_PLATFORM_WEB));
				List<AccountSessionEntity> accountList = PersistUtil.get(criteria);
				if (accountList!=null && accountList.size()>0) { //在线
					AccountSessionEntity entity=accountList.get(0);
					String extraJson=entity.getExtra();
					JSONObject jsonObject =  JSONObject.fromObject(extraJson);  

					if(jsonObject.containsKey("isApp") && !StringUtils.isEmpty(jsonObject.getString("isApp"))){
						info.setOnline(1);
					}
				}
			}
			outList.add(info);
		}
		return outList;
	}


	@Override
	public FinanceTaskCount inquireFinanceTaskCount1() throws Exception {
		return null;
	}


	@Override
	public PageList<FinanceTask> inquireFinanceTaskList(Integer type, String companyName, PageCriteria page)
			throws Exception {
		if (null == type) {
			type = 0;
		}

		//获取当前登入用户角色
		Long accountId = FinanceSessionContext.getAccountId();
		List<RoleListDto> rl = permissionAction.inquireAccountRoleList(accountId);
		StringBuffer finalStates = new StringBuffer("");
		for (RoleListDto rlt : rl) {
			for (ApiFinanceStateEnum finalState : ApiFinanceStateEnum.values()) {
				if (rlt.getRoleName().equals(finalState.getView())) {
					finalStates.append(finalState.getCode()).append(",");
				}
				if (rlt.getRoleName().equals(ApiFinanceStateEnum.RYW.getView()) || rlt.getRoleName().equals(ApiFinanceStateEnum.YY.getView()) || rlt.getRoleName().equals(ApiFinanceStateEnum.ZJ.getView())) {
					finalStates.append(ApiFinanceStateEnum.SCCWYY.getCode()).append(",");
				}

				if (rlt.getRoleName().equals(ApiFinanceStateEnum.RYW.getView()) || rlt.getRoleName().equals(ApiFinanceStateEnum.ZJ.getView())) {
					finalStates.append(ApiFinanceStateEnum.SCCW.getCode()).append(",");
				}

				if (rlt.getRoleName().equals(ApiFinanceStateEnum.RYW.getView()) || rlt.getRoleName().equals(ApiFinanceStateEnum.YY.getView())) {
					finalStates.append(ApiFinanceStateEnum.SCYY.getCode()).append(",");
				}

				if (rlt.getRoleName().equals(ApiFinanceStateEnum.ZJ.getView()) || rlt.getRoleName().equals(ApiFinanceStateEnum.YY.getView())) {
					finalStates.append(ApiFinanceStateEnum.CWYY.getCode()).append(",");
				}
			}
		}


		if (finalStates.length() > 0) {
			finalStates.deleteCharAt(finalStates.length() - 1);
		}

		List<PermissionOutput> permissionList=	permissionAction.inquireCurrentOperationList(); //查询模块权限
		List<FinanceTask> dataListOfOnePage=new ArrayList<FinanceTask>();

		String[] arr=null;
		if(permissionList != null){
			arr=new String[permissionList.size()];
			for(int i=0; i<permissionList.size(); i++){
				if(permissionList.get(i) != null) {
					arr[i]=permissionList.get(i).getPermissionId();
				}
			}
		}

		Session session = SessionRepository.getCurrentSession();

		StringBuffer sqlstr = new StringBuffer("");

		//1.查询是否有融资模块权限
		if(ArrayUtils.contains(arr, ApiModuleTypeEnum.RZ.getCode()) && (type == 0 || type == 1)){
			if (sqlstr.length() > 0) {
				sqlstr.append(" UNION ALL ");
			}
			sqlstr.append("SELECT IFNULL(null,'1') taskType, a.APPLICATION_DT applicationDateTime, IFNULL(null,null) deliveryAddress, IFNULL(null,null) pickupMethod, IFNULL(null,null) buyer, IFNULL(null,null) updator, IFNULL(null,null) updateDateTime, IFNULL(null,null) creator, a.APPLICATION_DT createDateTime, IFNULL(null,null) pickupId, IFNULL(null,null) temporaryCreditlineEvaluationId, IFNULL(null,null) temporaryCreditline, IFNULL(null,null) creditLine, IFNULL(null,null) gradeEvaluationId, a.ENTERPRISE_NAME enterpriseName, a.ENTERPRISE_ID enterpriseId, IFNULL(null,null) frName, IFNULL(null,null) loanNoticeId, a.FINANCE_ID financeId, b.FINANCE_AUDIT_ID financeAuditId, b.AUDIT_NUMBER auditNumber, b.FINAL_STATE finalState, b.CALLBACK callback, a.PRODUCT_TYPE productType, a.APPLICATION_AMOUNT applicationAmount, IFNULL(null,0) loanAmount FROM FIN_FINANCE_APPLICATION a, fin_finance_audit b WHERE a.FINANCE_STATE IN (1, 23) AND a.FINANCE_ID = b.FINANCE_ID AND b.FINAL_STATE IS NOT NULL").append(" UNION ALL ");
			sqlstr.append("SELECT IFNULL(null,'1') taskType, a.APPLICATION_DT applicationDateTime, IFNULL(null,null) deliveryAddress, IFNULL(null,null) pickupMethod, IFNULL(null,null) buyer, IFNULL(null,null) updator, IFNULL(null,null) updateDateTime, IFNULL(null,null) creator, a.APPLICATION_DT createDateTime, IFNULL(null,null) pickupId, IFNULL(null,null) temporaryCreditlineEvaluationId, IFNULL(null,null) temporaryCreditline, IFNULL(null,null) creditLine, IFNULL(null,null) gradeEvaluationId, a.ENTERPRISE_NAME enterpriseName, a.ENTERPRISE_ID enterpriseId, IFNULL(null,null) frName, IFNULL(null,null) loanNoticeId, a.FINANCE_ID financeId, IFNULL(null,null) financeAuditId, IFNULL(null,null) auditNumber, IFNULL(b.FINAL_STATE, 1) finalState, b.CALLBACK callback, a.PRODUCT_TYPE productType, a.APPLICATION_AMOUNT applicationAmount, IFNULL(null,0) loanAmount FROM FIN_FINANCE_APPLICATION a, fin_finance_audit b WHERE a.FINANCE_ID NOT IN (SELECT c.FINANCE_ID FROM fin_finance_audit c) AND a.FINANCE_STATE IN (1, 23) GROUP BY a.FINANCE_ID");
		}

		//2.查询是否有放款模块权限
		if(ArrayUtils.contains(arr, ApiModuleTypeEnum.FK.getCode()) && (type == 0 || type == 2)){
			if (sqlstr.length() > 0) {
				sqlstr.append(" UNION ALL ");
			}
			sqlstr.append("SELECT IFNULL(null,'2') taskType, a.APPLY_DT applicationDateTime, IFNULL(null,null) deliveryAddress, IFNULL(null,null) pickupMethod, IFNULL(null,null) buyer, IFNULL(null,null) updator, IFNULL(null,null) updateDateTime, IFNULL(null,null) creator, a.CREATE_DT createDateTime, IFNULL(null,null) pickupId, IFNULL(null,null) temporaryCreditlineEvaluationId, IFNULL(null,null) temporaryCreditline, IFNULL(null,null) creditLine, IFNULL(null,null) gradeEvaluationId, a.ENTERPRISE_NAME enterpriseName, a.ENTERPRISE_ID enterpriseId, IFNULL(null,null) frName, a.LOAN_NOTICE_ID loanNoticeId, a.FINANCE_ID financeId, IFNULL(null,null) financeAuditId, a.LOAN_NOTICE_NUMBER auditNumber, a.FINAL_STATE finalState, a.CALLBACK callback, b.PRODUCT_TYPE productType, IFNULL(null,0) applicationAmount, a.LOAN_AMOUNT loanAmount FROM FIN_LOAN_NOTICE a, fin_finance_application b WHERE ISNULL(a.AUDITOR_ID) AND a.FINANCE_ID = b.FINANCE_ID");
		}

		//3.查询是否有提货模块权限
		if(ArrayUtils.contains(arr, ApiModuleTypeEnum.TH.getCode()) && (type == 0 || type == 3)){
			if (sqlstr.length() > 0) {
				sqlstr.append(" UNION ALL ");
			}
			sqlstr.append("SELECT IFNULL(null,'3') taskType, a.APPLICANT_DT applicationDateTime, IFNULL(null,null) deliveryAddress, IFNULL(null,null) pickupMethod, IFNULL(null,null) buyer, IFNULL(null,null) updator, IFNULL(null,null) updateDateTime, IFNULL(null,null) creator, a.APPLICANT_DT createDateTime, a.PICKUP_ID pickupId, IFNULL(null,null) temporaryCreditlineEvaluationId, IFNULL(null,null) temporaryCreditline, IFNULL(null,null) creditLine, IFNULL(null,null) gradeEvaluationId, a.ENTERPRISE_NAME enterpriseName, a.ENTERPRISE_ID enterpriseId, IFNULL(null,null) frName, IFNULL(null,null) loanNoticeId, a.FINANCE_ID financeId, IFNULL(null,null) financeAuditId, a.PICKUP_NUMBER auditNumber, a.FINAL_STATE finalState, a.CALLBACK callback, b.PRODUCT_TYPE productType, IFNULL(null,0) applicationAmount, IFNULL(null,0) loanAmount FROM FIN_PICKUP_APPLICATION a, fin_finance_application b WHERE a.FINANCE_ID = b.FINANCE_ID AND PICKUP_TYPE = 1 AND (APPLICATION_STATE = 1 OR (EXCHANGE_STATUS IN (1, 2, 3) AND APPLICATION_STATE = 2))");
		}

		//4.企业待审核用户查询是否模块权限
		if(ArrayUtils.contains(arr, ApiModuleTypeEnum.QYYH.getCode()) && (type == 0 || type == 4)){
			if (sqlstr.length() > 0) {
				sqlstr.append(" UNION ALL ");
			}
			sqlstr.append("SELECT IFNULL(null,'4') taskType, a.CREATE_DT applicationDateTime, IFNULL(null,null) deliveryAddress, IFNULL(null,null) pickupMethod, IFNULL(null,null) buyer, IFNULL(null,null) updator, IFNULL(null,null) updateDateTime, IFNULL(null,null) creator, a.CREATE_DT createDateTime, IFNULL(null,null) pickupId, IFNULL(null,null) temporaryCreditlineEvaluationId, IFNULL(null,null) temporaryCreditline, IFNULL(null,null) creditLine, IFNULL(null,null) gradeEvaluationId, a.ENTERPRISE_NAME enterpriseName, a.ENTERPRISE_ID enterpriseId, a.LEGAL_PERSON frName, IFNULL(null,null) loanNoticeId, IFNULL(null,null) financeId, IFNULL(null,null) financeAuditId, a.AUDITNUMBER auditNumber, a.FINAL_STATE finalState, a.CALLBACK callback, IFNULL(null,null) productType, IFNULL(null,0) applicationAmount, IFNULL(null,0) loanAmount FROM FIN_ENTERPRISE a WHERE AUDIT_STATE IN (1, 2) AND ENABLED = 1");
		}

		//5.用户等级审核查询是否模块权限
		if(ArrayUtils.contains(arr, ApiModuleTypeEnum.YHDJ.getCode()) && (type == 0 || type == 5)){
			if (sqlstr.length() > 0) {
				sqlstr.append(" UNION ALL ");
			}
			sqlstr.append("SELECT IFNULL(null,'5') taskType, a.EVALUATION_DT applicationDateTime, IFNULL(null,null) deliveryAddress, IFNULL(null,null) pickupMethod, IFNULL(null,null) buyer, IFNULL(null,null) updator, IFNULL(null,null) updateDateTime, IFNULL(null,null) creator, a.EVALUATION_DT createDateTime, IFNULL(null,null) pickupId, IFNULL(null,null) temporaryCreditlineEvaluationId, IFNULL(null,null) temporaryCreditline, a.CREDIT_LINE creditLine, a.GRADE_EVALUATION_ID gradeEvaluationId, b.ENTERPRISE_NAME enterpriseName, b.ENTERPRISE_ID enterpriseId, b.FR_NAME frName, IFNULL(null,null) loanNoticeId, IFNULL(null,null) financeId, IFNULL(null,null) financeAuditId, a.AUDITNUMBER auditNumber, a.FINAL_STATE finalState, a.CALLBACK callback, IFNULL(null,null) productType, IFNULL(null,0) applicationAmount, IFNULL(null,0) loanAmount FROM FIN_ENTERPRISE_GRADE_EVALUATION a, FIN_ENTERPRISE b WHERE a.AUDIT_STATE IN (1, 2) AND a.ENTERPRISE_ID = b.ENTERPRISE_ID");
		}

		//6.临时额度调整查询是否模块权限
		if(ArrayUtils.contains(arr, ApiModuleTypeEnum.LSED.getCode()) && (type == 0 || type == 6)){
			if (sqlstr.length() > 0) {
				sqlstr.append(" UNION ALL ");
			}
			sqlstr.append("SELECT IFNULL(null,'6') taskType, a.EVALUATION_DT applicationDateTime, IFNULL(null,null) deliveryAddress, IFNULL(null,null) pickupMethod, IFNULL(null,null) buyer, IFNULL(null,null) updator, IFNULL(null,null) updateDateTime, IFNULL(null,null) creator, a.EVALUATION_DT createDateTime, IFNULL(null,null) pickupId, a.TEMPORARY_CREDITLINE_EVALUATION_ID temporaryCreditlineEvaluationId, a.TEMPORARY_CREDITLINE temporaryCreditline, IFNULL(null,null) creditLine, IFNULL(null,null) gradeEvaluationId, b.ENTERPRISE_NAME enterpriseName, b.ENTERPRISE_ID enterpriseId, b.FR_NAME frName, IFNULL(null,null) loanNoticeId, IFNULL(null,null) financeId, IFNULL(null,null) financeAuditId, a.AUDITNUMBER auditNumber, a.FINAL_STATE finalState, a.CALLBACK callback, IFNULL(null,null) productType, IFNULL(null,0) applicationAmount, IFNULL(null,0) loanAmount FROM FIN_ENTERPRISE_TEMPORARY_CREDITLINE_EVALUATION a, fin_enterprise b WHERE a.AUDIT_STATE IN (1, 2) AND a.ENTERPRISE_ID = b.ENTERPRISE_ID");
		}

		//7.销售提货
		if(ArrayUtils.contains(arr, ApiModuleTypeEnum.XSTH.getCode()) && (type == 0 || type == 7)){
			if (sqlstr.length() > 0) {
				sqlstr.append(" UNION ALL ");
			}
			sqlstr.append("SELECT IFNULL(null,'7') taskType, a.CREATE_DT applicationDateTime, a.DELIVERY_ADDRESS deliveryAddress, IFNULL(null,'自提') pickupMethod, a.BUYER buyer, a.UPDATOR updator, a.UPDATE_DT updateDateTime, a.CREATOR creator, a.CREATE_DT createDateTime, a.PICKUP_ID pickupId, IFNULL(null,null) temporaryCreditlineEvaluationId, IFNULL(null,null) temporaryCreditline, IFNULL(null,null) creditLine, IFNULL(null,null) gradeEvaluationId, a.ENTERPRISE_NAME enterpriseName, a.ENTERPRISE_ID enterpriseId, IFNULL(null,null) frName, IFNULL(null,null) loanNoticeId, IFNULL(null,null) financeId, IFNULL(null,null) financeAuditId, a.PICKUP_NUMBER auditNumber, a.FINAL_ID finalState, a.CALLBACK callback, a.PRODUCT_TYPE productType, IFNULL(null,0) applicationAmount, IFNULL(null,0) loanAmount FROM FIN_PICKUP_APPLICATION_WAREHOUSE a WHERE PICKUP_STATE IN (2, 10)");
		}

		sqlstr.append(")t WHERE t.finalState IN(").append(finalStates.toString() + ") ORDER BY applicationDateTime DESC");
		String sqlstr1 = "SELECT count(*) c FROM (" + sqlstr.toString();
		List<Object> datas2 = session.createSQLQuery(sqlstr1).addScalar("c").list();
		PageList<FinanceTask> fts = null;
		for (Object l : datas2) {
			fts = new PageList<>(page, ((BigInteger)l).intValue());
		}
		
		sqlstr.insert(0, "SELECT * FROM (");
		sqlstr.append(" LIMIT " + (page.getPageIndex() - 1)*page.getPageSize() + ", " + page.getPageSize());
		List<Object> datas = session.createSQLQuery(sqlstr.toString()).addScalar("taskType").addScalar("applicationDateTime").addScalar("deliveryAddress").addScalar("pickupMethod").addScalar("buyer").addScalar("updator").addScalar("updateDateTime").addScalar("creator").addScalar("createDateTime").addScalar("pickupId").addScalar("temporaryCreditlineEvaluationId").addScalar("temporaryCreditline").addScalar("creditLine").addScalar("gradeEvaluationId").addScalar("enterpriseName").addScalar("enterpriseId").addScalar("frName").addScalar("loanNoticeId").addScalar("financeId").addScalar("financeAuditId").addScalar("auditNumber").addScalar("finalState").addScalar("callback").addScalar("productType").addScalar("applicationAmount").addScalar("loanAmount").list();
		for (Object l : datas) {
			Object[] os = (Object[])l;
			FinanceTask task = new FinanceTask();
			task.setTaskType((String)os[0]);
			task.setApplicationDateTime((Date)os[1]);
			task.setEnterpriseName((String)os[14]);
			task.setEnterpriseId(((BigInteger)os[15]).longValue());
			task.setAuditNumber((String)os[20]);
			task.setFinalState(((BigInteger)os[21]).longValue());
			if ((Byte)os[22] != null) {
				task.setCallback((Byte)os[22] == 0x00 ? Boolean.FALSE : Boolean.TRUE);
			} else {
				task.setCallback(Boolean.FALSE);
			}
			
			if ("1".equals((String)os[0])) {
				if (os[19] != null) {
					task.setFinanceAuditId(((BigInteger)os[19]).longValue());
				}
				task.setProductType(((Byte)os[23]).intValue());
				task.setFinanceId(((BigInteger)os[18]).longValue());
				task.setApplicationAmount((BigDecimal)os[24]);
				
				List<FinanceBulkstockEntity> fbes = financeBulkstockService.inquireFinanceBulkstockList(task.getFinanceId());
				if (fbes != null && fbes.size() > 0) {
					task.setBulkstockName(fbes.get(0).getBulkstockName());
				}
				for (FinanceBulkstockEntity c: fbes) {
					FinanceBulkstock bulkstock = BulkstockCastor.toFinanceBulkstock(c);
					FinanceBulkstockView view = new FinanceBulkstockView(bulkstock.getBulkstockName(), bulkstock.getQuantity(), bulkstock.getUnit());
					task.getBulkstocks().add(view);
				}
			} else if ("2".equals((String)os[0])) {
				task.setLoanNoticeId(((BigInteger)os[17]).longValue());
				task.setFinanceId(((BigInteger)os[18]).longValue());
				task.setProductType(((Byte)os[23]).intValue());
				task.setProductName(ProductTypeEnum.valueOf(task.getProductType()).getValue());
				task.setLoanAmount((BigDecimal)os[25]);
				
				List<FinanceBulkstockEntity> fbes = financeBulkstockService.inquireFinanceBulkstockList(task.getFinanceId());
				if (fbes != null && fbes.size() > 0) {
					task.setBulkstockName(fbes.get(0).getBulkstockName());
				}

				// 融资货物
				for (FinanceBulkstockEntity c: fbes) {
					FinanceBulkstock bulkstock = BulkstockCastor.toFinanceBulkstock(c);
					FinanceBulkstockView view=new FinanceBulkstockView(bulkstock.getBulkstockName(),bulkstock.getQuantity(),bulkstock.getUnit());
					task.getBulkstocks().add(view);
				}
			}  else if ("3".equals((String)os[0])) {
				task.setFinanceId(((BigInteger)os[18]).longValue());
				task.setPickupId(((BigInteger)os[9]).longValue());
				task.setProductType(((Byte)os[23]).intValue());
				
				PickupApplicationEntity pickup = pickupApplicationService.inquirePickupApplication(task.getPickupId());
				
				task.setPickupMethod(pickup.getPickupMethod().getValue());
				List<FinanceBulkstockEntity> fbes = financeBulkstockService.inquireFinanceBulkstockList(task.getFinanceId());
				if (fbes != null && fbes.size() > 0) {
					task.setBulkstockName(fbes.get(0).getBulkstockName());
				}

				//查询提货信息
				// 融资货物
				List<FinanceBulkstockEntity> bulkstockList = financeBulkstockService.inquireFinanceBulkstockList(task.getFinanceId());
				for (FinanceBulkstockEntity c : bulkstockList) {
					FinanceBulkstock bulkstock = BulkstockCastor.toFinanceBulkstock(c);
					FinanceBulkstockView view=new FinanceBulkstockView(bulkstock.getBulkstockName(),bulkstock.getQuantity(),bulkstock.getUnit());
					task.getBulkstocks().add(view);
				}
				List<Long> inventoryIds = pickupInventoryService.inquirePickupInventoryIdList(task.getPickupId());
				if (inventoryIds != null && inventoryIds.size() > 0) {
					task.setContainerInventorysCount(inventoryIds.size());
				} else {
					task.setContainerInventorysCount(0);
				}
			}  else if ("4".equals((String)os[0])) {
				task.setFrName((String)os[16]);
			}  else if ("5".equals((String)os[0])) {
				task.setCreditLine((BigDecimal)os[12]);
				task.setGradeEvaluationId(((BigInteger)os[13]).longValue());
			}  else if ("6".equals((String)os[0])) {
				task.setTemporaryCreditlineEvaluationId(((BigInteger)os[10]).longValue());
				task.setTemporaryCreditline((BigDecimal)os[11]);
			}  else if ("7".equals((String)os[0])) {
				task.setDeliveryAddress((String)os[2]);
				task.setPickupMethod((String)os[3]);
				task.setBuyer((String)os[4]);
				task.setUpdator((String)os[5]);
				task.setUpdateDateTime((Date)os[6]);
				task.setCreator((String)os[7]);
				task.setCreateDateTime((Date)os[8]);
				task.setProductType(((Byte)os[23]).intValue());
				task.setPickupId(((BigInteger)os[9]).longValue());
				
				BigDecimal pickupAmounts = BigDecimal.ZERO;
				BigDecimal pickupQuantitys = BigDecimal.ZERO;
				BigDecimal supervisionQuantitys = BigDecimal.ZERO;

				List<PickupBulkstockWarehouseEntity> pbwes = pickupBulkstockWarehouseService.inquirePickupBulkstockWarehouseList(task.getPickupId(), null);
				for (PickupBulkstockWarehouseEntity pbwe : pbwes) {
					session = SessionRepository.getCurrentSession();
					PickupBulkstockWarehouseDetail pbwd = new PickupBulkstockWarehouseDetail();
					BeanUtils.copyProperties(pbwe, pbwd);
					pbwd.setProductType(pbwe.getProductType().ordinal());

					StringBuffer sql1 = new StringBuffer();
					sql1.append("SELECT (T1.WEIGHT - IFNULL(T2.PICKUP_QUANTITY, 0)) as WEIGHT, T1.LOCATION_ID as LOCATION_ID, BULKSTOCK_NAME, SPECIFICATION, PRODUCT_TYPE, BULKSTOCK_INFO_ID, WAREHOUSE_NAME, T1.FINANCE_ID AS FINANCE_ID, T1.FINANCE_NUMBER AS FINANCE_NUMBER, T1.APPLICATION_DT AS APPLICATION_DT, T1.LOCATION_AREA AS LOCATION_AREA, T1.LOCATION_NAME AS LOCATION_NAME FROM (SELECT SUM(WEIGHT) AS WEIGHT, LOCATION_ID, BULKSTOCK_NAME, SPECIFICATION, c.PRODUCT_TYPE, BULKSTOCK_INFO_ID, WAREHOUSE_NAME, a.FINANCE_ID AS FINANCE_ID, a.FINANCE_NUMBER AS FINANCE_NUMBER, c.APPLICATION_DT AS APPLICATION_DT, a.LOCATION_AREA AS LOCATION_AREA, a.LOCATION_NAME AS LOCATION_NAME FROM fin_container_inventory a, fin_container_bulkstock b, fin_finance_application c WHERE a.INVENTORY_ID = b.INVENTORY_ID");
					sql1.append(" AND a.LOCATION_ID ='").append(pbwe.getLocationId() + "'");
					sql1.append(" AND a.FINANCE_NUMBER ='").append(pbwe.getFinanceNumber() + "'");
					sql1.append(" AND a.FINANCE_ID = c.FINANCE_ID AND c.FINANCE_STATE = 9 GROUP BY a.FINANCE_ID, LOCATION_ID) T1 LEFT JOIN (SELECT SUM(PICKUP_QUANTITY) AS PICKUP_QUANTITY, LOCATION_ID, FINANCE_NUMBER FROM fin_pickup_bulkstock_warehouse d, FIN_PICKUP_APPLICATION_WAREHOUSE e where d.PICKUP_ID = e.PICKUP_ID AND e.PICKUP_STATE NOT IN(1, 13) GROUP BY FINANCE_NUMBER, LOCATION_ID) T2 ON T1.LOCATION_ID = T2.LOCATION_ID AND T1.FINANCE_NUMBER = T2.FINANCE_NUMBER WHERE T1.LOCATION_ID IS NOT NULL AND T1.LOCATION_ID <> '';");

					List<Object> datas1 = session.createSQLQuery(sql1.toString()).addScalar("WEIGHT").addScalar("LOCATION_ID").addScalar("BULKSTOCK_NAME").addScalar("PRODUCT_TYPE").addScalar("BULKSTOCK_INFO_ID").addScalar("WAREHOUSE_NAME").addScalar("FINANCE_ID").addScalar("FINANCE_NUMBER").addScalar("LOCATION_NAME").addScalar("LOCATION_AREA").addScalar("APPLICATION_DT").addScalar("SPECIFICATION").list();
					for (Object l1 : datas1) {
						Object[] os1 = (Object[])l1;
						pbwd.setSupervisionQuantity((BigDecimal) os1[0]);
						pbwd.setLocationName((String) os1[8]);
						pbwd.setLocationArea((String) os1[9]);
						pbwd.setFinanceApplicationDate((Date) os1[10]);
						pbwd.setSpecifician((String) os1[11]);
					}

					pickupAmounts = pickupAmounts.add(pbwd.getPickupAmount());
					pickupQuantitys = pickupQuantitys.add(pbwd.getPickupQuantity());
					supervisionQuantitys = supervisionQuantitys.add(pbwd.getSupervisionQuantity());

					task.getBulkstockList().add(pbwd);
					SessionRepository.closeCurrentSession();
				}

				task.setPickupAmounts(pickupAmounts);
				task.setPickupQuantitys(pickupQuantitys);
				task.setSupervisionQuantitys(supervisionQuantitys);
			}
			fts.add(task);
		}
		
		SessionRepository.closeCurrentSession();
		return fts;
	}

}
